Running sum (1 Viewer)


The Mailman - AWF VIP
Local time
Today, 06:26
Aug 11, 2003
I have been looking half a day and cannot really find a proper solution... Well not quite true, I have a solution that works... but I dont like it.

In Oracle you can use the sum() Partition by to create a running sum... or running count()... In SQL Server this doesnt seem possible.... :(

What I have now:
Select country_code
     , myDatum
     , count(*) as CountOfDay
     , ( select count(*) 
         from t_table i 
         where i.country_code = tni.country_code 
           and i.date_assigned < mydatum + 1 ) x
from  (select *, cast( floor ( cast ( date_assigned as float ) ) as datetime) as mydatum 
       from t_table ) tni
where country_code = 'FR'
group by country_code, mydatum
order by mydatum
Note that Date_assigned is a date/time field that is truncated to a date field.

Is there any other (more clean?/faster/more efficent) way to do a running sum in SQL Server??


Users who are viewing this thread

Top Bottom