牛客SQL134——满足条件的用户的试卷完成数和题目练习数

题目描述
https://www.nowcoder.com/practice/5c03f761b36046649ee71f05e1ceecbf

思路:# 请你找到高难度SQL试卷得分平均值大于80并且是7级的红名大佬,统计他们的2021年试卷总完成次数和题目总练习次数,只保留2021年有试卷完成记录的用户。结果按试卷完成数升序,按题目练习数降序。

先去找满足条件的红名大佬id,然后在根据id去统计他们的做题数
需要注意在where的时候and(year(p.submit_time)=2021 or p.submit_time is null),里面的or要包在and 里面

# 请你找到高难度SQL试卷得分平均值大于80并且是7级的红名大佬,统计他们的2021年试卷总完成次数和题目总练习次数,只保留2021年有试卷完成记录的用户。结果按试卷完成数升序,按题目练习数降序。

#统计他们的2021年试卷总完成数
select r.uid,count(distinct r.exam_id) as exam_cnt,count(distinct p.submit_time ) as question_cnt
from exam_record as r left join practice_record as p on r.uid=p.uid
where r.uid in(
    # 先找到高难度SQL试卷,平均分大于80,level=7
select uid
from user_info
where level=7 and uid in
(select r.uid  from exam_record as r join examination_info as e on r.exam_id=e.exam_id
where e.tag='SQL' and e.difficulty='hard'
group by r.uid
having avg(score)>=80
)
) and year(r.submit_time)=2021 and (year(p.submit_time)=2021 or p.submit_time is null)
group by r.uid
order by exam_cnt,question_cnt desc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值