问题描述
- Msql月度统计问题,求大神解答。
-
现有统计后的数据;
month recsum total
2015-2 100 100
2015-3 2000 2000
2015-4 150 3000
2015-5 2000 50000想得到结果:
month recsum total
2015-2 100 100
2015-3 2100 2100
2015-4 2250 5100
2015-5 4250 55100
解决方案
SELECT t1.month,
SUM(t2.recsum) recsum,
SUM(t2.total) total
FROM table1 t1
JOIN table1 t2
ON t1.month >= t2.month
GROUP BY t1.month
时间: 2024-09-17 04:08:36