题解 | #统计复旦用户8月练题情况#
统计复旦用户8月练题情况
https://www.nowcoder.com/practice/53235096538a456b9220fce120c062b3
select up.device_id,up.university,count(q.device_id) question_cnt,sum(if(result = 'right',1,0)) right_question_cnt from user_profile up left join question_practice_detail q on up.device_id=q.device_id where up.university='复旦大学' and (date like '2021-08-%' or date is null) group by up.device_id; 这个题目有难度,如果直接用date是8月份去筛选的话,没有答题的同学会被忽略,下面这种解法也很好: select up.device_id,up.university,count(q.device_id) question_cnt,sum(if(result = 'right',1,0)) right_question_cnt from user_profile up left join question_practice_detail q on up.device_id=q.device_id and date like '2021-08-%' where up.university='复旦大学' group by up.device_id;