题解 | #获取当前薪水第二多的员工的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