Cumulative sum over days

别说谁变了你拦得住时间么 提交于 2019-12-05 16:58:16

Well, I think this would work, not sure how the performance would be though:

SELECT t1.date, sum(t2.count)
FROM mytable t1 INNER JOIN mytable t2 ON t2.date <= t1.date
GROUP BY t1.date

It's possible to solve this problem without join.

SET @cumulative_sum := 0;
SELECT date, @cumulative_sum := @cumulative_sum + count AS cumulative_sum
FROM table
ORDER BY date ASC

Self join with a <= and sum the row would accomplish this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!