Running Totals in SQL

Running Totals in SQL
Select Base.CustomerID ,Base.DocDt , TotalforCust , SUM(TTotal) RunningTotal from
(
Select CustomerID , DocDt ,SUM(Amount) TotalforCust from Transales
GROUP By CustomerID , DocDt
)Base
Inner join
(
Select CustomerID , DocDt ,SUM(Amount) TTotal from Transales
GROUP By CustomerID , DocDt
) RnT on Base.CustomerID = RnT.CustomerID and RnT.DocDt <= Base.DocDt

GROUP BY Base.CustomerID ,Base.DocDt , TotalforCust

Comments

Popular posts from this blog

Shared / Static Class in vb.net/C#

Xamarin Forms : PopUp Page with RG.Plugins.Popup

Text was truncated or one or more characters had no match in the target code page.". (SQL Server Import and Export Wizard)