题解 | #牛客的课程订单分析(七)#
牛客的课程订单分析(七)
http://www.nowcoder.com/practice/d6f4a37f966145da8900ba9edcc4c068
分成两部分:第一部分找到满足4个条件的user_id,成交、成交两次以上、对应产品、日期。然后用user_id取到对应的数据并进行统计,得出相应的结果。
count(*) from order_info o left join client c
on o.client_id = c.id
where o.user_id in (
select user_id from (
select user_id, count(user_id) as cnt, min(date) as first_buy_date from order_info
where status = "completed" and date > "2025-10-15" and product_name <> "JS"
group by user_id) success
where cnt >= 2)
and o.status = "completed"
and o.date > "2025-10-15"
and o.product_name <> "JS"
group by source
order by source