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

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

https://www.nowcoder.com/practice/4ae8cff2505f4d7cb68fb0ec7cf80c57

with
t1 as(
    select
        user_id,
        product_name,
        status,
        date,
        count(status)over(partition by user_id) as counts
    from
        order_info
    where
        status='completed'
        and
        product_name in ('C++','Java','Python')
        and
        timestampdiff(day,'2025-10-15',date)>0
),
t2 as(
    select distinct
        user_id
    from
        t1
    where
        counts>=2
    order by
        user_id
)

select
    *
from
    order_info
where
    exists (select 1 from t2 where t2.user_id = order_info.user_id)
    and
    status='completed'
    and
    product_name in ('C++','Java','Python')
    and
    timestampdiff(day,'2025-10-15',date)>0
order by
    id

全部评论

相关推荐

粉红恶魔派星星:炸了,偶遇kpi面。面试官一直在忙自己的事情。1.手写责任链 2.手写快排 3.linux定时任务的命令 4.springboot的定时任务 5.问了一条实习
今天你投了哪些公司?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务