Calculate running total / running balance

后端 未结 6 1732
粉色の甜心
粉色の甜心 2020-11-22 10:01

I have a table:

create table Transactions(Tid int,amt int)

With 5 rows:

insert into Transactions values(1, 100)
insert into         


        
6条回答
  •  死守一世寂寞
    2020-11-22 10:36

    With the 2012 SUM and OVER functions you can now nest sum and counts.

    SELECT date, sum(count(DISTINCT unique_id)) OVER (ORDER BY date) AS total_per_date
    FROM dbo.table
    GROUP BY date
    

提交回复
热议问题