现在运营想要了解复旦大学的每个用户在8月份练习的总题目数和回答正确的题目数情况,请取出相应明细数据,对于在8月份没有练习过的用户,答题数结果返回0。
select
up.device_id,
'复旦大学' as university,
count(question_id) as question_cnt,
sum(if (qpd.result = 'right', 1, 0)) as right_question_cnt
from
user_profile as up
left join question_practice_detail as qpd on qpd.device_id = up.device_id
and month (qpd.date) = 8
where
up.university = '复旦大学'
group by
up.device_id