select
t1.device_id,
t1.university,
sum(case when t2.result is not null then 1 else 0 end),
sum(case when t2.result = 'right' then 1 else 0 end)
FROM user_profile t1
LEFT JOIN question_practice_detail t2 
ON t1.device_id = t2.device_id and MONTH(t2.date) = '08'
where t1.university = '复旦大学'
group by t1.device_id