知识点

  1. 和上一题一样先把表全部按照条件筛选完,然后按照时间正序row_number排序一下,再加上一列计数列用count窗口函数写
  2. 第一次购买时间就是排序1,次数大于等于2

代码

select user_id, date as first_buy_date, cnt
from 
      (select 
      user_id, date,
      row_number() over(partition by user_id order by date) as rn,
      count(*) over(partition by user_id) as cnt
      from order_info
      where date>'2025-10-15'
      and status='completed'
      and product_name in ('C++','Java','Python')
      ) as t 
where t.rn=1 and t.cnt>=2
order by user_id