题解 | #牛客的课程订单分析(五)#
牛客的课程订单分析(五)
https://www.nowcoder.com/practice/348afda488554ceb922efd2f3effc427
with a as (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 status = 'completed'
and date > '2025-10-15'
and product_name in ('C++','Java','Python'))
select user_id,
min(date) as first_buy_date,
max(date) as second_buy_date,
cnt
from a
where cnt >= 2 and rn <= 2
group by user_id,cnt
order by user_id;
