\使用case when来定义最后一列
\子查询中不能出现group by,因为只会返回条件对应的第一个值
select t.id,
t.is_group_buy,
(case when t.is_group_buy = 'No'
then c.name
else null
end) as client_name
from (
select *,
count(id)over(partition by user_id) as cnt
from order_info
where date > '2025-10-15'
and status = 'completed'
and product_name in ('C++','Java','Python')
) as t
left join client c
on t.client_id = c.id
where t.cnt >= 2
order by t.id
京公网安备 11010502036488号