题解 | 牛客的课程订单分析(五)
牛客的课程订单分析(五)
https://www.nowcoder.com/practice/348afda488554ceb922efd2f3effc427
with t as (
select user_id,date,row_number() over(partition by user_id order by date) as rnk
from order_info
where date>'2025-10-15' and status='completed' and product_name in ('C++','Java','Python')
)
select user_id,min(case when rnk=1 then date end) as first_buy_date,min(case when rnk=2 then date end) as second_buy_date,count(*) as cnt
#逻辑上可以不加min,加是为了显式告诉编译器确定唯一防止fullgroupby报错。
from t
group by user_id
having cnt>=2
order by user_id



字节跳动公司福利 1371人发布