Re: Running totals on a select count statement
From: Steve Kass (skass_at_drew.edu)
Date: 03/10/04
- Next message: zack: "Re: Running totals on a select count statement"
- Previous message: Newbie: "Re: More help with query"
- In reply to: zack: "Running totals on a select count statement"
- Next in thread: zack: "Re: Running totals on a select count statement"
- Reply: zack: "Re: Running totals on a select count statement"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 10 Mar 2004 13:43:34 -0500
Zack,
Since the sum of counts is really just another count, maybe this will
work:
select
OrderId,
OrderDate,
count(OrderAmt) as OrderCount,
(select count(T2.OrderAmt)
from T T2
where T2.OrderID <= T1.OrderID
) as RunningTotalOrderCount
from T T1
group by OrderID, OrderDate
SK
zack wrote:
>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: zack: "Re: Running totals on a select count statement"
- Previous message: Newbie: "Re: More help with query"
- In reply to: zack: "Running totals on a select count statement"
- Next in thread: zack: "Re: Running totals on a select count statement"
- Reply: zack: "Re: Running totals on a select count statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|