题解 | 牛客的课程订单分析(五)
select user_id, min(date) as first_buy_date, min(next_date) as second_buy_date, max(number) as cnt from ( select *, row_number() over(partition by user_id order by date) as number, lead(date,1) over(partition by user_id order by date) as next_date from order_info where date>'2025-10-15' and status='completed' and product_name in ('Python','Java','C++') order by user_id) as t group by user_id having count(*)>=2 order by user_id;