这题和上题类似,但是考察了wherehaving的区别。

where是要在group by的前面,而having是出现在group by的后面。所以我们这里只能用having跟在group by的后面。

select 
university,
difficult_level,
count(q.question_id) / count(distinct q.device_id) as 'avg_answer_cnt'
from 
user_profile as u 
join question_practice_detail as q
on u.device_id = q.device_id

join question_detail as qd
on q.question_id = qd.question_id

group by university, difficult_level
having university = '山东大学';