题解 | #统计复旦用户8月练题情况#
统计复旦用户8月练题情况
https://www.nowcoder.com/practice/53235096538a456b9220fce120c062b3
SELECT u.device_id, u.university, COALESCE(q.question_cnt, 0) AS question_cnt, COALESCE(q.right_question_cnt, 0) AS right_question_cnt FROM user_profile AS u LEFT OUTER JOIN ( SELECT device_id, SUM( CASE WHEN date LIKE '2021-08%' THEN 1 ELSE 0 END ) AS question_cnt, SUM( CASE WHEN result = 'right' THEN 1 ELSE 0 END ) AS right_question_cnt FROM question_practice_detail WHERE date LIKE '2021-08%' GROUP BY device_id ) AS q ON u.device_id = q.device_id WHERE u.university = '复旦大学';