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

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

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

相关推荐

Java面试先知:我也是和你一样的情况,hr 说等开奖就行了
点赞 评论 收藏
分享
10-21 00:37
已编辑
山东大学 C++
小浪_Coding:你问别人,本来就是有求于人,别人肯定没有义务免费回答你丫, 有点流量每天私信可能都十几,几十条的,大家都有工作和自己的事情, 付费也是正常的, 就像你请别人搭把手, 总得给人家买瓶水喝吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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