题解 | #牛客的课程订单分析(六)#
牛客的课程订单分析(六)
http://www.nowcoder.com/practice/c5736983c322483e9f269dd23bdf2f6f
- 先利用窗口函数计算出符合条件的用户购买数
select *, count(*) over(partition by user_id) as cnt from order_info
where date > '2025-10-15'
and product_name in ('C++','Java','Python')
and status = 'completed'
- 再利用外联结将两个表联结,注意组团(YES)的标识为0,不在client表内,联结后的值为空值,符合题目要求。
select a.id, a.is_group_buy, b.name as client_name from
(select *, count(*) over(partition by user_id) as cnt from order_info
where date > '2025-10-15'
and product_name in ('C++','Java','Python')
and status = 'completed') a left join client b on a.client_id = b.id
where a.cnt >= 2
order by a.id asc;