题解 | #月均完成试卷数不小于3的用户爱作答的类别#

月均完成试卷数不小于3的用户爱作答的类别

http://www.nowcoder.com/practice/b1d13efcfa0c4ecea517afbdb9090845

感觉自己写的乱七八遭,运行效率还不错…… 另外,牛客网这题目就不能出的没有疑义吗?月均数>=3搞得我以为每个月都要>=3

-- 1,查询出uid,tag,month,完成情况
-- 2,找出月均完成大于等于3的用户
-- 3,统计这些用户的类别情况(包括没完成的)

with tmp as-- 统计每个用户每个月的完成数
(
select uid,mon,sum(compl)as total from
(select uid,tag,month(start_time)as mon,if(submit_time is null,0,1)as compl 
from exam_record 
left join examination_info 
using(exam_id)
 )c
 group by uid,mon
 )
select tag,count(tag)as tag_cnt from examination_info ei
join exam_record er
on er.uid in (select distinct uid from tmp where total>=3) and ei.exam_id=er.exam_id
group by tag
order by tag_cnt desc

全部评论
是啊,我也以为每个月都要大于等于3
点赞 回复 分享
发布于 2022-04-24 15:42

相关推荐

谁知道呢_:要掉小珍珠了,库库学三年,这个结果
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务