您的位置:首页 > 数据库 > MySQL

mysql 分组统计(直播内容状态,带上内容id),count case when group_concat sql

2018-03-22 16:46 731 查看
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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: