题解 | #满足条件的用户的试卷完成数和题目练习数#

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

https://www.nowcoder.com/practice/5c03f761b36046649ee71f05e1ceecbf

# #高难度SQL试卷得分平均值大于80并且是7级的红名大佬
# #统计2021年的试卷完成次数
# #count(*) as exam_cnt
# select uid,count(*) as exam_cnt
# from exam_record as er 
# join examination_info as ei on er.exam_id=ei.exam_id
# join user_info as ui on er.uid=ui.uid
# where ei.difficulty="hard"
# and ei.tag="SQL"
# group by er.uid
# having avg(er.score)>80

# left join

# #题目总练习次数
# (select count(distinct uid) as question_cnt
# from practice_record as pr
# join user_info as ui on pr.uid=ui.uid
# group by pr.uid )

# order by exam_cnt,question_cnt DESC;

select 
    uid,
    exam_cnt,
    if(question_cnt is null, 0, question_cnt)
from
(select 
    uid,
    count(submit_time) as exam_cnt
from exam_record
where YEAR(submit_time) = 2021
group by uid) t

left join

(select
    uid,
    count(submit_time) as question_cnt
from practice_record
where YEAR(submit_time) = 2021
group by uid) t2 using(uid)

where uid in
(
select
    uid
from exam_record
join examination_info using(exam_id)
join user_info using(uid)
where tag = 'SQL' and difficulty = 'hard' and `level` = 7
group by uid
having avg(score) >= 80
)
order by exam_cnt asc, question_cnt desc

全部评论

相关推荐

投票
我要狠拿offer:如果不是必须去成都绝对选九院呀,九院在四川top1研究所了吧
点赞 评论 收藏
分享
牛客963010790号:为什么还要收藏
点赞 评论 收藏
分享
oppo 应用软开 22*15+0.5*12
拿到了ssp完美:真的坎坷,但是你至少拿到这么多offer了!
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务