题解 | #统计复旦用户8月练题情况#

https://www.nowcoder.com/practice/53235096538a456b9220fce120c062b3

题意: 统计复旦8月练题情况

  1. 注意点: 如果直接用left join question_practice_detail 后在where中进行过滤month(qpd.date)=8, 则学生信息中,只要8月份没有答题的也会被过滤掉
  2. 可以使用 left join question_practice_detail qpd on up.device_id=qpd.device_id and month(qpd.date)=8, 这样会先过滤b表8月份有答题的, 而不会把第一张表中8月份无答题的过滤掉
  3. case when 用法万能, 是我的最爱, 但是这个连接是全连接, 效率会低点
    select up.device_id,
        university,
        sum(case when qpd.device_id is not null and month(qpd.date)=8 then 1 else 0 end) as question_cnt,
        sum(case when qpd.result = 'right' and month(qpd.date)=8 then 1 else 0 end) as right_question_cnt
    from user_profile up
    left join question_practice_detail qpd on up.device_id=qpd.device_id
    where up.university='复旦大学'
    group by up.device_id
全部评论
你好,请问这里八月答题不正确的是不是也会返回0啊,这个地方不太理解
点赞 回复 分享
发布于 2025-03-24 10:22 辽宁

相关推荐

评论
7
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务