结合订单分析(六)已计算出用户id,是否是拼单,对应的符合条件的总订单数cnt 及对应客户端的名称
第二部,因为拼单的话客户端名字为NULL 故使用case when 对不是拼单的类别重新命名,再根据其计数即可
SELECT
case when c.client_name is NULL then 'GroupBuy' else c.client_name end source,
count(c.id)
from
(
SELECT
a.id,
a.is_group_buy,
a.cnt,
b.name client_name
FROM
(
SELECT
*,
count(product_name) over(partition by user_id) cnt
from order_info
where status='completed'
and date>'2025-10-15'
and product_name in('C++','Java','Python')
)a
left join client b
on a.client_id=b.id
where a.cnt>=2
group by 1
order by 1
)c
group by 1
order by 1