题解 | #牛客的课程订单分析(四)#
牛客的课程订单分析(四)
http://www.nowcoder.com/practice/c93d2079282f4943a3771ca6fd081c23
- 第一次购买的日期辅助表
- 合计购买数量的辅助表
- 合并后筛选
with first_buy_date as (
select user_id,min(date) first_date from order_info
where status = 'completed' and
product_name in ('C++','Python','Java') and
date > '2025-10-15' group by user_id),
buy_count as (
select user_id,count(date) buy_count from order_info
where status = 'completed' and
product_name in ('C++','Python','Java') and
date > '2025-10-15' group by user_id)
-
select a.user_id,first_date,buy_count from
buy_count a left join first_buy_date b
on a.user_id == b.user_id
where buy_count>=2
order by a.user_id