Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Running Totals
Message
 
 
À
03/09/2009 15:05:14
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Divers
Thread ID:
01422486
Message ID:
01422490
Vues:
47
>Hey all,
>
>I have a query that needs running totals by the SomeId and month. I think SQL Server complicates the matter and I might not be able to do it. The query is like this:
>
>Select SomeID, Month , *Running Total Here*
>From ( Some really crazy complicated query ) CrazyQuery
>Order by SomeId, Month
>
>This seems like it should be fairly simple but from what I understand, I'm going to have to create another crazyquery and reference the dates.. Am I incorrect about this?
>
>Thanks,
>Dan

For SQL Server 2005 and up you may also try
; with cte_Complex as (my Crazy Query)

select C.SomeID, C.Month, (select sum(Amount) as Running Total 
from cte_Complex CC where CC.Month <C.Month and C.SomeID = CC.SomeID)  as RunningTotal from cte_Complex C
order by C.SomeID, C.Month
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform