使用窗口函数的解决方案:
select
if(t.client_id=0,'GroupBuy',c.name) as source,
count(distinct t.id) as cnt
from
(select
user_id,
client_id,
id,
count(id) over (partition by user_id) as u_cnt
from order_info
where product_name in ('C++','Python','Java')
and status='completed'
and date>='2025-10-15'
) t
left join client c on t.client_id=c.id
where t.u_cnt>=2
group by 1