SQL Sum of last X Sum of records

前端 未结 2 1883
耶瑟儿~
耶瑟儿~ 2021-01-13 14:52

I\'ve looked for a while and I cannot find the answer to this question (maybe I\'m not searching the correct terms or something). Basically, I have a database that has any n

2条回答
  •  有刺的猬
    2021-01-13 15:23

    Here is an idea using correlated subqueries:

    with bydays as ()
    select bd.*,
           (select sum(NumMeasured) from (select top 100 * from bydays bd2 where bd2.date <= bd.date order by date desc) t
           ) as Measured100,
           (select sum(NumPassingd) from (select top 100 * from bydays bd2 where bd2.date <= bd.date order by date desc) t
           ) as Measured100
    from bydays
    

提交回复
热议问题