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

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

http://www.nowcoder.com/practice/4ae8cff2505f4d7cb68fb0ec7cf80c57

第一步 求订单次数大于等于2的user_id
第二步  把求得user_id 当做where筛选条件 
第三步  最后别忘记加上产品名字,订单状态,日期,因为你第二步筛选只固定了user_id
select *
from order_info 
where user_id in (
                    select order_sum.user_id
                    from (
                          # 求次数大于2的user_id
                           select user_id,count(date) as ct
                           from order_info
                           where product_name in ('C++','Java','Python')
                           and status='completed'
                           and date>'2025-10-15'
                           group by user_id
                           ) as order_sum
                    where order_sum.ct>=2
                   )
 # 重复筛选条件
and product_name in ('C++','Java','Python')
and status='completed'
and date>'2025-10-15'
order by id;


全部评论
借鉴了一下别人的经验用having 少做1个子查询 select * from order_info where user_id in ( select user_id from order_info where product_name in ('C++','Java','Python') and status='completed' and date>'2025-10-15' group by user_id having count(*)>=2 ) and product_name in ('C++','Java','Python') and status='completed' and date>'2025-10-15' order by id;
点赞 回复 分享
发布于 2021-10-15 12:04

相关推荐

机械打工仔:有说的你怀疑一下就行了,直接问也太实诚了
点赞 评论 收藏
分享
zYvv:双一流加大加粗再标红,然后广投。主要是获奖荣誉不够,建议开始不用追求大厂,去别的厂子刷下实习。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 11:22
怎么这么多逆天求职者,救救我救救我救救我😭
flmz_Kk:哈哈哈哈哈哈,这么多求职者,肯定有那一两个逆天的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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