第一版答案 总结:输出正确,但代码有重复(冗余),需要改进。
SELECT o.id,
o.is_group_buy,
case
when is_group_buy='No' then c.name
when is_group_buy='Yes' then NULL
end client_name
FROM order_info o
LEFT JOIN client c
ON o.client_id=c.id
WHERE o.user_id in (
select user_id from order_info
where date>'2025-10-10'
and product_name IN('C++','Java','Python')
and status='completed'
GROUP BY user_id
having count(id)>=2
)
and date>'2025-10-10' #此段代码重复
and product_name IN('C++','Java','Python')
and status='completed'
order by o.id asc