题解 | #获取当前薪水第二多的员工的emp_no以及其对应的薪水salary#

牛客的课程订单分析(五)

http://www.nowcoder.com/practice/348afda488554ceb922efd2f3effc427

select user_id,min(date) as first_buy_date,
max(date) as second_buy_date,cnt
from (select user_id,date,row_number() over (partition by user_id order by date) sort_number,
     count(*) over (partition by user_id) cnt
     from order_info where product_name in ("C++","Python","Java")
     and date > "2025-10-15" and status = "completed") t1
     where t1.cnt>1 and sort_number<3 GROUP BY user_id order by user_id

参考了一下别人的方法,使用窗口函数会简便好多
按照日期排序,取出前两个,小的作为first_buy_date,大的作为second_buy_date

全部评论

相关推荐

点赞 评论 收藏
分享
程序员小白条:太晚了,看别人找到实习了才投的话,自己本身就没啥准备,计划太晚咯,只能吞苦果子
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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