题解 | #牛客的课程订单分析(五)#

牛客的课程订单分析(五)

http://www.nowcoder.com/practice/348afda488554ceb922efd2f3effc427

with t1 as (
select user_id,min(date) as first_buy_date,count(product_name) as cnt
from order_info
where date>'2025-10-15'
and status='completed'
and product_name in ('C++','Java','Python')
group by user_id
having count(user_id)>=2
),
t2 as (
select user_id,date,row_number() over (partition by user_id order by date) rk
from order_info
where date >'2025-10-15'
and status='completed'
and product_name in ('C++','Java','Python')

),
t3 as (
select user_id,date
from t2
    where rk=2
)
select a.user_id,first_buy_date,date as second_buy_date,cnt
from t1 a 
left join t3 b 
on a.user_id=b.user_id
group by a.user_id
order by a.user_id
全部评论

相关推荐

喜欢走神的孤勇者练习时长两年半:池是池,发是发,我曾池,我现黑
点赞 评论 收藏
分享
10-25 00:32
香梨想要offer:感觉考研以后好好学 后面能乱杀,目前这简历有点难
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务