题解 | #牛客的课程订单分析(五)#
牛客的课程订单分析(五)
http://www.nowcoder.com/practice/348afda488554ceb922efd2f3effc427
select
b.user_id
,b.m
,a.date
,b.c
from (
select
*
,row_number() over(partition by user_id order by date) r
from order_info
where date > '2025-10-15'
and status = 'completed'
and product_name in ('C++','Python','Java')
order by user_id
) a # 将第二个时间放进去
right join (
select
user_id
,min(date) m
,count(user_id) c
from order_info
where date > '2025-10-15'
and status = 'completed'
and product_name in ('C++','Python','Java')
group by user_id
having count(user_id) >=2
order by user_id
) b #第四题的表格
on a.user_id =b.user_id
where a.r = 2
order by b.user_id