1,select count(*) as count,month(addtime) as 月份 from TB group
by month(addtime).
如果只有2,3月份的话,提出啦的数据时这样的
count 月份
100 2
400 3
我想要的结果是这样的:
count 月份
0 1
100 2
400 3
0 4
0 5,
............... 就是没有的月份就补0,但是12个月都要出来,要12条数据,从1,12排
6 回答
慕容3067478
TA贡献1773条经验 获得超3个赞
select count(*) as count,1 as 月份 from TB where month(addtime) =1
union all
select count(*) as count,2 as 月份 from TB where month(addtime) =2
union all
select count(*) as count,3 as 月份 from TB where month(addtime) =3
- 6 回答
- 0 关注
- 641 浏览
添加回答
举报
0/150
提交
取消