select if(a.is_group_buy='Yes','GroupBuy',b.name)source,
count(a.cnt)
from (select id, user_id, is_group_buy ,client_id,
count(*)over(partition by user_id)cons,
row_number()over()cnt
from order_info
where
date > '2025-10-15' and
status = 'completed' and
product_name in('C++','Java','Python'))a
left join client b on a.client_id = b.id
where a.cons > 1
group by if(a.is_group_buy='Yes','GroupBuy',b.name)
order by if(a.is_group_buy='Yes','GroupBuy',b.name) 先筛选出符合条件的user_id表
然后左连接关联client表
用if 函数或者case 提出数据



京公网安备 11010502036488号