一条sql统计按月统计出新增用户数

select date_format(created_at,'%Y-%m') as created_at,count(id) as num
from users
group by date_format(created_at,'%Y-%m')
order by date_format(created_at,'%Y-%m')

改进后

select date_format(created_at,'%Y-%m') as created_at,count(id) as num
from users
group by created_at
order by created_at

原文地址:https://www.cnblogs.com/shaoyikai/p/8126327.html