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

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

https://www.nowcoder.com/practice/c93d2079282f4943a3771ca6fd081c23

# 先找到满足要求的用户id
with t1 as (
    select user_id, count(id) 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 cnt >= 2
)# 找到没开始的一次购买日期
select t1.user_id, a.first_buy_date, t1.cnt
from t1
left join (
    select user_id, min(date) as first_buy_date
    from order_info
    where user_id in (select user_id from t1)
    and date >= '2025-10-15'
    and status = 'completed'
    and product_name in ("C++", "Java", "Python")
    group by user_id
) as a
on t1.user_id = a.user_id
order by t1.user_id;


全部评论

相关推荐

allin秋招的大菠萝很爱交友:后续,已拿offer ~查看图片
点赞 评论 收藏
分享
练习JAVA时长两年半:qps 30000
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务