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

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

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

select up.device_id,
       university,
       count(question_id) as question_cnt,
       sum(if(result = 'right',1,0))as right_question_cnt
from user_profile up
left join question_practice_detail qpd
    using(device_id)
where university = '复旦大学'
      and (month(date) = 8
      or month(date) is null)
group by up.device_id, university

注意点:

  1. 正确题目计数,不用count,用sum和if组合
  2. 因有未答题同学,left join保险
  3. where筛选月份时,注意增加null条件,避免漏掉未答题同学,用or连接
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-24 13:40
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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