情景描述:如下表Table_Name有id,name,CreatedDate三个字段.现在需要按照月份记录总数量,得到一个包含月份,数量的表。
select MONTH(CreatedDate) as '月份',
COUNT(*) as '数量'
from Table_Name
group by MONTH(CreatedDate)
order by month(CreatedDate)
升级情况:查出2023年个个月份的总数。其实也很好解决,加一个where条件即可
select MONTH(CreatedDate) as '月份',
COUNT(*) as '数量'
from Table_Name where CreatedDate > '2023-01-01'
group by MONTH(CreatedDate)
order by month(CreatedDate)
总结:尽最大努力满足甲方需求,让系统做到无人为干扰