查询每个用户在exam_publish_id为(1,2,3)时,按user_id分组统计不同status个数(即相同status+1)。表结构如下:
期待结果如下:
user_id status1 status2 status3 27047 2 1 0 27410 0 2 1 27047 1 1 1
ringa_lee
终于试出来了。。。答案如下:
SELECT user_id, COUNT(IF(status=0,true, null)) AS 'right_count', COUNT(IF(status=1,true, null)) AS 'error_count', COUNT(IF(status=2,true, null)) AS 'absenteeism_count' FROM online_exam_user_detail WHERE exam_publish_id in (1, 2, 3) GROUP BY user_id;
终于试出来了。。。答案如下: