题解 | #牛客的课程订单分析(三)#
牛客的课程订单分析(三)
http://www.nowcoder.com/practice/4ae8cff2505f4d7cb68fb0ec7cf80c57
1.2025-10-15之后,同一个用户下单状态为购买成功的C++,java,python的订单信息
# SELECT * # FROM order_info # WHERE status = "completed" # and product_name IN ("C++", "Java", "Python") # and date > '2025-10-15'
2.在2025-10-15以后,同一个用户下单2个以及2个以上状态为
购买成功的C++课程或Java课程或Python课程的user_id
# select user_id # from order_info # where date > '2025-10-15' # and product_name in ('C++', 'Python', 'Java') # and status = 'completed' # group by user_id # having count(*) > 1
3.用子查询将1和2连接起来,最后用id排序
select T.* from ( select * from order_info where date > '2025-10-15' and product_name in ('C++', 'Python', 'Java') and status = 'completed' ) T where user_id in ( select user_id from order_info where date > '2025-10-15' and product_name in ('C++', 'Python', 'Java') and status = 'completed' group by user_id having count(*) > 1 ) order by id