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

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

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;
全部评论

相关推荐

04-25 18:13
五邑大学 Java
后来123321:大二两段实习太厉害了,我现在大二连面试都没有
点赞 评论 收藏
分享
牛客10001:G了+1,被前端/客户端给捞起来了,不太想面
投递美团等公司7个岗位 美团求职进展汇总
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务