方法一:找出满足条件的user_id,再对表进一步筛选。
select * from order_info where user_id in ( select user_id from order_info where product_name in ('C++','Python','Java') and status = 'completed' and date > '2025-10-15' group by user_id having count(user_id) > 1 ) and product_name in ('C++','Python','Java') and status = 'completed' and date > '2025-10-15' order by id;
方法二:窗口函数, 计数而已
select t.id,t.user_id,t.product_name,t.status,t.client_id,t.date from (select *, count(*) over(partition by user_id) as num from order_info where product_name in ('C++','Java','Python') and status='completed' and date >'2025-10-15') as t where t.num >= 2 order by t.id;