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

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

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

终于不用看题解完成一个难题,题目很绕。

需要解决的点

1.用户

条件:月均,已完成试卷数>=3 来筛选出用户

select uid from  ( select uid,month(submit_time) from exam_record em
  group by uid,month(submit_time)
  having count(submit_time)>=3) ec

因为是月均,所以按照uid和month()分组

然后把这部分用户的所有信息挑出来作为新表与examination_info 表进行连接

select *  from exam_record ex 
 where uid in (select uid from  ( select uid,month(submit_time) from exam_record em
  group by uid,month(submit_time)
  having count(submit_time)>=3) ec)

这里用到的是in

2.爱作答的类别

两表连接,最终的代码

select tag,count(start_time ) as tag_cnt  from examination_info a
join (select *  from exam_record ex 
 where uid in (select uid from  ( select uid,month(submit_time) from exam_record em
  group by uid,month(submit_time)
  having count(submit_time)>=3) ec)) b
on a.exam_id =b.exam_id 
group by tag
order by tag_cnt desc
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 11:16
点赞 评论 收藏
分享
05-26 22:25
门头沟学院 Java
Java小肖:不会是想叫你过去把你打一顿吧,哈哈哈
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 15:58
投个小米提前批试试水,先投一个岗位看看形势,不行就再沉淀一下投第二个岗位,莫辜负
Java抽象带篮子:我嘞个骚刚,已经开始研发6g了吗
投递小米集团等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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