结题思路:使用lead窗口函数取得每个日期的下一个日期,然后min每个用户全部最小日期得到第一次购买,min下一个日期得到第二次购买
SELECT user_id, min(date) as first_buy_date, min(second_buy_date)as second_buy_date, count(*) as cnt from ( select user_id, date, lead(date,1) over(partition by user_id order by date)as second_buy_date from order_info where date > '2025-10-15' and product_name in ('C++','Java','Python') and status = 'completed' )t group by user_id having count(*)>=2 order by user_id