根据题意,先把购买成功次数在两次以上的用户筛选出来,在通过join和原表连接,将没有成功次数在两次以上的用户剔除,在把客户端表left join 连接起来,最后三表连接后,在写一遍约束条件即可
select o.id, o.is_group_buy, client.name
from
order_info o
join
(select user_id
from order_info
where date > '2025-10-15'
and product_name in ('C++','Java','Python')
and status = 'completed'
group by user_id
having count(user_id)>=2
) a
on o.user_id=a.user_id
left join
client
on o.client_id=client.id
where o.date > '2025-10-15'
and o.product_name in ('C++','Java','Python')
and o.status = 'completed'
order by o.id;

京公网安备 11010502036488号