题解 | #统计每个用户的平均刷题数#
统计每个用户的平均刷题数
https://www.nowcoder.com/practice/f4714f7529404679b7f8909c96299ac4
select university, difficult_level, count(qpd.question_id)/count(distinct(qpd.device_id)) from question_practice_detail as qpd left join user_profile as up on qpd.device_id = up.device_id left join question_detail as qd on qpd.question_id = qd.question_id where university = '山东大学' group by difficult_level # sql语句的书写顺序: # select >> from >> where >> group by >> having >> order by >> limit # 注意: # 1. select和from是必须的; # 2. where和having不能同时使用; # 3. having和group by联合使用; # sql语句的解析顺序 : # from >> on>> join >> where >> group by >> having >> select >> distinct >> order by >> limit # 注意:虽然select在having后执行,但是mysql中仍然可以在having中使用select语句定义的别名#sql#