Running totals on a select count statement
From: zack (anonymous_at_discussions.microsoft.com)
Date: 03/10/04
- Next message: Newbie: "Help with query"
- Previous message: vengal: "working on sql server"
- Next in thread: Steve Kass: "Re: Running totals on a select count statement"
- Reply: Steve Kass: "Re: Running totals on a select count statement"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 10 Mar 2004 06:11:06 -0800
Im trying to get a running total to work.
example that I found @ http://www.databasejournal.com/features/mssql/article.php/3112381 :
select OrderId, OrderDate, O.OrderAmt
,(select sum(OrderAmt) from Orders
where OrderID <= O.OrderID)
'Running Total'
from Orders O
OrderId OrderDate OrderAmt Running Total
----------- -------------------- ---------- -------------
1 2003-10-11 08:00:00 10.50 10.50
2 2003-10-11 10:00:00 11.50 22.00
3 2003-10-11 12:00:00 1.25 23.25
What Im looking to do is something like this:
select OrderId, OrderDate, count(O.OrderAmt)
,(select sum(Count(OrderAmt)) from Orders
where OrderID <= O.OrderID)
'Running Total'
from Orders O
I need the first select to count and then run a sum on that count.
Thanks for help in advance.
zack
- Next message: Newbie: "Help with query"
- Previous message: vengal: "working on sql server"
- Next in thread: Steve Kass: "Re: Running totals on a select count statement"
- Reply: Steve Kass: "Re: Running totals on a select count statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|