解法一:子查询
1、查询订单数大于等于2 的用户id
select user_id
from order_info
group by user_id
having count(status)>=2)
2、查询在2025-10-15以后,状态为购买成功的C++课程或Java课程或Python课程,用户id 在1表范围内的订单信息
select * 
from order_info
where date>'2025-10-15' and status='completed'
and (product_name in ('C++','Java','Python'))
and user_id in
(select user_id
from order_info
group by user_id
having count(status)>=2)
order by id
解法二:窗口函数
1、统计2025-10-15以后,状态为购买成功的C++课程或Java课程或Python课程,每个用户的订单数量
select * , count(status) over (partition by user_id) as cnt
from order_info
where date>'2025-10-15' and status='completed'
and (product_name in ('C++','Java','Python'))
2、在1表中查询订单数量大于等于2 的订单信息并排序
select id,user_id,product_name,status,client_id,date
from
(select * , count(status) over (partition by user_id) as cnt
from order_info
where date>'2025-10-15' and status='completed'
and (product_name in ('C++','Java','Python'))) as a
where cnt>=2
order by id;