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

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

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

  1. 查询在2025-10-15以后,同一个用户下单2个以及2个以上状态为购买成功的C++课程或Java课程或Python课程的用户id
select user_id 
from order_info
where date>'2025-10-15'
and status ='completed'
and product_name in ('C++','Java','Python')
group by user_id
having count(*)>=2
  1. 查询在2025-10-15以后,同一个用户下单2个以及2个以上状态为购买成功的C++课程或Java课程或Python课程的 所有信息
select *
from order_info
where user_id in (
    select user_id 
    from order_info
    where date>'2025-10-15'
    and status ='completed'
    and product_name in ('C++','Java','Python')
    group by user_id
    having count(*)>=2
)
and date>'2025-10-15'
and status ='completed'
and product_name in ('C++','Java','Python')
  1. 将2作为新表和client表连接, 通过group by和case when 得到结果
select (case when name is null then 'GroupBuy' else name end) as source ,count(*)
from (
    select *
    from order_info
    where user_id in (
        select user_id 
        from order_info
        where date>'2025-10-15'
        and status ='completed'
        and product_name in ('C++','Java','Python')
        group by user_id
        having count(*)>=2
    )
    and date>'2025-10-15'
    and status ='completed'
    and product_name in ('C++','Java','Python')
) order_new
left join client c
on order_new.client_id = c.id
group by (case when name is null then 'GroupBuy' else name end) 
order by source asc
全部评论

相关推荐

04-13 18:10
门头沟学院 Java
想熬夜的小飞象在秋招:被腾讯挂了后爸妈以为我失联了
点赞 评论 收藏
分享
用户64975461947315:这不很正常吗,2个月开实习证明,这个薪资也还算合理,深圳Java好多150不包吃不包住呢,而且也提前和你说了没有转正机会,现在贼多牛马公司骗你说毕业转正,你辛辛苦苦干了半年拿到毕业证,后面和你说没hc了😂
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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