all groups > sql server programming > june 2005 >
You're in the

sql server programming

group:

Calculating Trends


Re: Calculating Trends Anith Sen
6/2/2005 4:56:41 PM
sql server programming:
Do:

SELECT dt, ( SELECT SUM( number )
FROM tbl t2
WHERE t2.dt <= t1.dt )
FROM tbl t1 ;

--
Anith

Re: Calculating Trends Ross Presser
6/2/2005 5:26:06 PM
[quoted text, click to view]

"Calculating Running Totals"
http://www.sqlteam.com/item.asp?ItemID=3856

Summary: Depending on the size of your data, this is one instance where a
cursor may actually be worth using. This is because the cursor will only
make one pass through the table, while any set-based solution has to join
the table with itself - which can produce millions of temporary rows, at
least momentarily.

Most of the time, an even better idea is to let the SQL side just retrieve
the un-summarized data, and let the consuming application produce the
running total. In effect, this is moving the cursor from the database side
Calculating Trends <CrazyHorse>
6/2/2005 10:36:17 PM
Hello,

I am looking for the most efficient way to calculate a trend based upon
individual figures in a table. Here is an example (e.g. sold items):

Data:
date number
------------- ----------
2001-01-01 3
2001-01-02 5
2001-01-03 10

expected result:

date totsl number of sold items
------------- ----------
2001-01-01 3
2001-01-02 8
2001-01-03 18

Any idea hoe I can solve that with the best performance possible?

Thanks

Re: Calculating Trends <CrazyHorse>
6/3/2005 8:31:13 AM
Hello,

thanks for your help.

[quoted text, click to view]

AddThis Social Bookmark Button