时间:2021-07-01 10:21:17 帮助过:4人阅读
select count(*) from groups where type in('001','002','003','004','005') and addtime>='20130101' and addtime <= '20130630'
select count(*) from groups where type in('001','002','003','004','005') and addtime>='20130101' and addtime <= '20130630'
你好,谢谢回复,这样查询出来就是一个总和,我想要单独的一个值
比如TYPE =001 一月份 总数是 20
TYPE=002 1月份 总数是500
TYPE=003 1月份 总数是3987
TYPE=004 1月份 总数是9898
TYPE=005 1月份 总数是123
select count(*) from groups where addtime>='20130101' and addtime <= '20130630' group by addtime,type
select type, left(addtime,6) as addtime, count(*) as cnt from groups group by 1, 2
那连in都不用了 group by type, DATE_FORMAT(addtime,‘m%’) 这样试一下
select count(*) from groups where addtime>='20130101' and addtime <= '20130630' group by MONTH(addtime),type
select count(*) from groups where addtime>='20130101' and addtime <= '20130630' group by substring(addtime,4,2),type
2中方式:
1、使用SQL写临时表
2、建立where条件相关的索引;
临时表是个不错的选择,数据处理完就自动释放了!
用group by+1
自己研究一下怎么写
实在不行用缓存减少查询...