我正在尝试为下表建立几个月的累积总和;
created_at Installs port
2011-02-01 00:00:00 2 7033
2012-02-05 00:00:00 8 7032
2012-03-01 00:00:00 1 7031
2012-05-05 00:00:00 2 8500
2012-06-01 00:00:00 4 7545
我使用以下查询;
SELECT
created_at,
Installs,
@total := @total + Installs AS cumulative
FROM
table, (SELECT @total:=0) AS t
这很好用,但是对于没有记录的月份,我没有得到任何金额。我想用最后一个“已知”值填补空白。
我的猜测是我需要创建一个临时表来引用一年中的每个月,然后加入它,但我无法正确解决这个问题。
你有什么想法 ?
谢谢