with rr as ( select *, count(id) over(partition by user_id) as cnt, row_number() over(partition by user_id order by date ) as t_rank from order_info where datediff(date,"2025-10-15")>0 and status = "completed" and product_name in ("C++","Java","Python") ) select user_id, min((case when t_rank = 1 then date end)) as first_buy_date, min((case when t_rank = 2 then date end)) as second_buy_date, cnt from rr where cnt > 1 group by user_id order by user_id asc;