题解 | 任意两个连续自然月练题次数大于1的用户

任意两个连续自然月练题次数大于1的用户

https://www.nowcoder.com/practice/a4cea6942a4f4354b0a0181aa5f446d2

select distinct device_id from
(select device_id,year1,month1,lag(month1)over(partition by device_id order by year1,month1) month2,lag(year1)over(partition by device_id order by year1,month1) year2 from
(select device_id,year(event_date) year1,month(event_date) month1,count(question_id) cnt from question_practice_detail
group by device_id,year(event_date),month(event_date)
having cnt>1) as newtable) as new
where (month1-month2=1 and year1=year2) or (month1-month2=-11 and year1-year2=1)
order by device_id desc

有两种情况会是连续的月份:1、本年内的两个月 2、12月和次年1月。

(month1-month2=1 and year1=year2) or (month1-month2=-11 and year1-year2=1)

month1为用month()取出的当前日期月份,month2是用lag()over()窗口函数取出的上一个做题数大于1的月份。

year同理

全部评论

相关推荐

不知道怎么取名字_:两个方向 1.简历针对性准备下 2.面试前也需要准备的 主要还是要看各个公司需求,看公司行业和岗位描述,那里面已经写了对技术的需求,一份简历,不可能和所有嵌入式岗位都匹配的
投递北京经纬恒润科技股份有限公司等公司6个岗位
点赞 评论 收藏
分享
程序员牛肉:你这简历有啥值得拷打的?在牛客你这种简历一抓一大把,也就是个人信息不一样而已。 关键要去找亮点,亮点啊,整个简历都跟流水线生产出来的一样。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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