Query the number of different statuses grouped by user_id (that is, the same status 1) for each user when the exam_publish_id is (1, 2, 3).
The table structure is as follows:
Expect the following results:
user_id status1 status2 status3
27047 2 1 0
27410 0 2 1
27047 1 1 1
怪我咯2017-05-24 11:34:47
Finally tried it out. . . The answer is as follows:
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;