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

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

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

相关推荐

你背过凌晨4点的八股文么:简历挂了的话会是流程终止,像我一样
点赞 评论 收藏
分享
ResourceUtilization:我嘞个董事长
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务