简单思路,先选出符合条件的user_id然后选符合条件的订单

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

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

简单思路,先选出符合条件的user_id,然后选出符合条件的订单信息,不太好的就是判断条件要用两遍

第一步,求和

    select user_id, count(1) ct
    from order_info
    where date > '2025-10-15' && status = 'completed'  && (product_name = 'C++' || product_name = 'Java' || product_name = 'Python')
    group by user_id

第二步,选出符合条件的user_id

    select user_id from (
    select user_id, count(1) ct
    from order_info
    where date > '2025-10-15' && status = 'completed'  && (product_name = 'C++' || product_name = 'Java' || product_name = 'Python')
    group by user_id
    )t1 
    where ct >= 2

第三步,选出相应信息,要left join 因为左表中有右表没有的连接条件

select o1.id,is_group_buy,name client_name from 
order_info o1 left join client c1
on o1.client_id = c1.id
where user_id in(
    select user_id from (
    select user_id, count(1) ct
    from order_info
    where date > '2025-10-15' && status = 'completed'  && (product_name = 'C++' || product_name = 'Java' || product_name = 'Python')
    group by user_id
    )t1 
    where ct >= 2
) && date > '2025-10-15' && status = 'completed'  && (product_name = 'C++' || product_name = 'Java' || product_name = 'Python'
全部评论

相关推荐

点赞 评论 收藏
分享
笑着秋招😊:我一直认为努力有回报是一件很幸福很幸福的事情,恭喜你
点赞 评论 收藏
分享
LuvSran:是人我吃。老师就是学校呆久了,就业方面啥都不懂,还自以为是为了我们就业好。我学校就一破双非,计科入行率10%都没有,某老师还天天点名,说是出勤率抬头率前排率高了,华为什么的大厂就会来,我们就是不好好上课才没有厂来招。太搞笑了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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