这一道题就是上一道题的扩展,理解了上一道题,就很容易做出来。
但是注意不要被上一步中cnt迷惑。
select source, count(source) as sum_cnt
from
(select
(case when is_group_buy = 'Yes' then 'GroupBuy'
when is_group_buy ='No' then name end) as source,
cnt
from client
right outer join
(select id, client_id, count(1) over (partition by user_id) as cnt, is_group_buy
from order_info
where date > '2025-10-15'
and status = 'completed'
and product_name in ('C++','Python','Java')) as b
on client.id = b.client_id
where cnt >= 2
order by b.id) as c
group by source
order by source;