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

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

http://www.nowcoder.com/practice/c5736983c322483e9f269dd23bdf2f6f

  1. 先利用窗口函数计算出符合条件的用户购买数
    select *, count(*) over(partition by user_id) as cnt from order_info
    where date > '2025-10-15'
    and product_name in ('C++','Java','Python')
    and status = 'completed'
  2. 再利用外联结将两个表联结,注意组团(YES)的标识为0,不在client表内,联结后的值为空值,符合题目要求。
    select a.id, a.is_group_buy, b.name as client_name from 
    (select *, count(*) over(partition by user_id) as cnt from order_info
    where date > '2025-10-15'
    and product_name in ('C++','Java','Python')
    and status = 'completed') a left join client b on a.client_id = b.id
    where a.cnt >= 2
    order by a.id asc;
全部评论

相关推荐

求求给个offer我...:有这60不如v我50
点赞 评论 收藏
分享
10-28 17:30
已编辑
华东交通大学 Java
iori2333:这太正常了 我字节面了四五轮 没有一次是在官网投递 都是hr主动捞
秋招笔试记录
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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