题解 | #牛客的课程订单分析(三)#
牛客的课程订单分析(三)
https://www.nowcoder.com/practice/4ae8cff2505f4d7cb68fb0ec7cf80c57
总是漏条件
select * from order_info where date>'2025-10-15'and product_name in ('C++','Python','Java') and status='completed' and 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(user_id)>=2) order by id
或者使用窗口函数
select t1.id, t1.user_id,t1.product_name,t1.status,t1.client_id,t1.date from ( select *,count(id) over(partition by user_id) as number from order_info where datediff(date,"2025-10-15")>0 and status ="completed" and product_name in ("C++","Java","Python") ) t1 where t1.number >1 order by t1.id