没想出什么好的办法,先查出来了符合count>=2的user_id,然后再查出来user_id的client_id,因为要是用一个表group by having count >= 2返回的client_id不全,查出来client_id就好办了,直接left join 如果是null说明client_id是0 那么就用if将值转换为“GroupBy”,然后count就好了

select if(name is null , 'GroupBuy',name) source , count(1) cnt from
(select client_id from order_info
where user_id in
(select user_id from order_info where (product_name = 'C++' or product_name = 'java' or product_name = 'Python') and date > '2025-10-15' and status = 'completed'
group by user_id having count(1) >= 2)
and (product_name = 'C++' or product_name = 'java' or product_name = 'Python') and date > '2025-10-15' and status = 'completed'
)temp
left join client on temp.client_id = client.id
group by name
order by source