题解 | #统计复旦用户8月练题情况#
统计复旦用户8月练题情况
https://www.nowcoder.com/practice/53235096538a456b9220fce120c062b3
-- 需要关联两张表,根据题目说没有练习过的用户,答题数结果返回0,所以我们用left join保全左边所有用户。 -- 限定条件:复旦大学 university='复旦大学',8月份练习,且答题正确result='right' --需要根据用户分组 group by device_id。 select t1.device_id,t1.university, count(t2.question_id) as question_cnt, sum(if(t2.result='right',1,0)) as right_question_cnt from user_profile as t1 left join question_practice_detail as t2 on t1.device_id = t2.device_id where t1.university = '复旦大学' and (month(t2.date)='08'or month(t2.date) is null ) group by t1.device_id;