mysql 问题 大佬来看看呗!

    我想统计每月总人数 要加上之前的人数

SELECT
DATE_FORMAT(createtime, '%Y%m') MONTH,
count(id) count
FROM
sysuser
WHERE
STATUS = '1'
AND ! ISNULL(createtime)
GROUP BY
MONTH

![图片说明](https://img-ask.csdn.net/upload/201704/14/1492136657_294955.png)

假设表名为Person,有两个字段month,count。

SELECT a.month,a.count, SUM(b.count) as result
FROM Person a JOIN Person b
ON a.month >= b.month
GROUP BY a.month

说明:
a, b 均为Person表的别名,result为累积和的别名,先做一个联合,然后分组求和

图片说明

这统计每个月的人数,有什么问题吗?

sql写的有点烂
select sum(date) from Test where
date_format(dateTime,'%Y-%m')=date_format(now(),'%Y-%m') or date_format(dateTime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m')

 ![图片说明](https://img-ask.csdn.net/upload/201704/14/1492140784_207821.png)

 上面图片对应的是字段和数据