题解 | #统计复旦用户8月练题情况#
统计复旦用户8月练题情况
https://www.nowcoder.com/practice/53235096538a456b9220fce120c062b3
select
a.device_id,
a.university,
coalesce(b.answ_num_Aug, 0) as answ_num_Aug,
coalesce(c.right_answ_num_Aug, 0) as right_answ_num_Aug
from
(
select
device_id,
university
from
user_profile
where
university = '复旦大学'
group by
1,
2
) a
left join (
select
device_id,
count(question_id) as answ_num_Aug
from
question_practice_detail
where
date between '2021-08-01' and '2021-08-31'
group by
1
) b on a.device_id = b.device_id
left join (
select
device_id,
count(question_id) as right_answ_num_Aug
from
question_practice_detail
where
date between '2021-08-01' and '2021-08-31'
and result = 'right'
group by
1
) c on a.device_Id = c.device_id