题解 | #月均完成试卷数不小于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
全部评论

相关推荐

霁华Tel:秋招结束了,好累。我自编了一篇对话,语言别人看不懂,我觉得有某种力量在控制我的身体,我明明觉得有些东西就在眼前,但身边的人却说啥也没有,有神秘人通过电视,手机等在暗暗的给我发信号,我有时候会突然觉得身体的某一部分不属于我了。面对不同的人或场合,我表现出不一样的自己,以至于都不知道自己到底是什么样子的人。我觉得我已经做的很好,不需要其他人的建议和批评,我有些时候难以控制的兴奋,但是呼吸都让人开心。
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务