本题思路如下: 首先利用窗口函数,统计出每个用户在指定条件下成功购买的个数(子查询里的语句) 接下来用case语句 判断 是否团购 最后一定要leftjoin client 不然order info表中的client_id为0的无法匹配到 然后再限制成功购买个数大于等于2的,groupby+orderby即可

select case when g.is_group_buy='Yes' then 'GroupBuy'
else c.name end Source,count(*)
from 
(select *,count(*) over(partition by user_id) cnt from 
order_info where date>'2025-10-15' and status='completed' and
product_name!='JS') g 
left join client c 
on g.client_id = c.id
where g.cnt>=2
group by Source
order by Source