mysql - How to implement this query with a sql
ringa_lee
ringa_lee 2017-05-24 11:32:47
0
1
552

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
ringa_lee
ringa_lee

ringa_lee

reply all(1)
刘奇

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;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template