题解 | #统计复旦用户8月练题情况#
统计复旦用户8月练题情况
https://www.nowcoder.com/practice/53235096538a456b9220fce120c062b3
SELECT u.device_id, u.university, IFNULL( ( SELECT COUNT(q.question_id) FROM question_practice_detail q LEFT JOIN user_profile u ON q.device_id = u.device_id WHERE u.university = '复旦大学' AND q.date > '2021-08-01' ), 0 ) AS question_cnt, IFNULL( ( SELECT COUNT(q.result) FROM question_practice_detail q LEFT JOIN user_profile u ON u.device_id = q.device_id WHERE u.university = '复旦大学' AND q.result = 'right' ), 0 ) AS right_question_cnt FROM user_profile u LEFT JOIN question_practice_detail q ON u.device_id = q.device_id WHERE u.university = '复旦大学' GROUP BY u.device_id