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

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

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

-- with临时表获得大佬id
with
t1 as
(select er.uid
from exam_record er left join examination_info ei on er.exam_id=ei.exam_id
left join user_info ui on er.uid = ui.uid
where tag='SQL' and difficulty ='hard' and level =7
group by uid
having avg(score) >80)

-- 两个子查询分别获得完成试卷数和题目数,sj试卷,tm题目
select uid,
(select count(1) from exam_record er where score is not null and er.uid=t1.uid and year(submit_time)=2021) as sj,
(select count(1) from practice_record pr where pr.uid=t1.uid and year(submit_time) =2021 ) as tm
from t1 order by sj,tm desc

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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