1. 程式人生 > >mysql 分組統計(直播內容狀態,帶上內容id),count case when group_concat sql

mysql 分組統計(直播內容狀態,帶上內容id),count case when group_concat sql

SELECT group_concat(case live_status when 0 then content_id end) as closed_ids, group_concat(case live_status when 1 then content_id when 2 then content_id end) as unclosed_ids, count(case live_status when 0 then 0 end) as closed_times, count(case live_status when 1 then 1 when 2 then 1 end) as unclosed_times, `d`.`name`, `content_id`, group_concat(content_id) as ids, `creator`, `affiliation` FROM `bd_content` right join `bd_user` ON `bd_content`.`creator` = `bd_user`.`user_id` right join `bd_dict`as `d` ON d.id=`bd_user`.affiliation WHERE ((((`affiliation` IN ('19', '20', '21', '22')) AND (`content_type`=1)) AND (`live_type` <> 2)) AND (`live_start` > 1519833600)) AND (`live_end` < 1521707605) GROUP BY `affiliation` LIMIT 10