Paste_Image.png
在mysql中實現如上數據累加效果,可使用set,定義用戶變量。
sql 語句:
SET @x = 0;
SELECT
t1.months,
t1.register_num ,
@x := @x+t1.register_num AS total
FROM
(
SELECT
DATE_FORMAT(createTime, "%Y%m") months,
count(id) AS register_num
FROM
t_user
GROUP BY
months asc
) t1