题解 | #牛客的课程订单分析(六)#
牛客的课程订单分析(六)
https://www.nowcoder.com/practice/c5736983c322483e9f269dd23bdf2f6f
# 判断'is_group_buy'字段 select o.id, o.is_group_buy, case when o.is_group_buy = 'No' then c.name -- 使用 CASE 表达式进行条件判断 else NULL end as client_name from order_info o left join client c -- left join:只有非拼团(is_group_buy为No)订单 on o.client_id = c.id where date > '2025-10-15' and status = 'completed' and product_name in ('C++', 'Java', 'Python') and user_id in ( -- 要显示除了user_id的信息,不能直接使用group by后的结果,参考上一题 select user_id from order_info where date > '2025-10-15' and status = 'completed' and product_name in ('C++', 'Java', 'Python') group by user_id having count(id) >= 2 ) order by id;