Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Ordina per anno, mese e somma cumulativa

Dato che stai utilizzando 2012, ecco un'opzione che utilizza window functions :

select
    yr,
    mth,
    sumamount,
    sum(sumamount) over (order by yr, mth rows unbounded preceding) runningsum
from (select year(noticedate) yr,
             month(noticedate) mth,
            sum(amount) sumamount
      from data123
      group by year(noticedate), month(noticedate)
) t
order by yr, mth