select t1.user_id,max(case when t1.date_rank=1 then t1.date else 0 end )as first_buy_date,max(case when t1.date_rank=2 then t1.date else 0 end )as second_buy_date,t1.number as cntfrom ( select *,count(id) over(partition by user_id) as number, row_number() over(partition by user_id order by da...