开窗函数
row_number()分区中不重复不间断的序号
lead(expr,n)分区中位于后n行的expr的值
select user_id, min(date) as first_buy_date, min(下一个日期) as second_buy_date, max(次数) as cnt from ( select *, row_number() over(partition by user_id order by date) as 次数, lead(date,1) over(partition by user_id order by date) as 下一个日期 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;