mysql group by count case when

数据库 投稿 11100 0 评论

mysql group by count case when


select count(extension_num) as callAll,sum(talk_length) as talkLength,
count(case when call_type=1 then 1 else null end) as callin,
count(case when call_type=0 then 1 else null end) as callout,
COUNT(case when call_type=0 and talk_length>0 then 1 else null end) as calloutYes,
COUNT(case when call_type=0 and talk_length=0 then 1 else null end) as calloutNo,
COUNT(case when call_type=1 and talk_length=0 then 1 else null end) as callinNo,
COUNT(case when call_type=1 and talk_length>0 then 1 else null end) as callInYes,
extension_num from t_call_call_record GROUP BY extension_num;

多条件


select count(id) totalCnt,COUNT(case when warehouse_type=0 then null else 1 end) fixedCnt,
COUNT(case WHEN warehouse_type=1 then 1 
WHEN warehouse_type=2 then 1
when warehouse_type=0 and use_status=1 then 1
else null end) usedCnt
 from storage_warehouse where `status`=0 and delete_status=0;

编程笔记 » mysql group by count case when

赞同 (64) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽