题解 | 牛客的课程订单分析(五)
SELECT b1.user_id, b1.first_buy_date, b1.second_buy_date, b1.cnt FROM ( SElECT user_id, product_name, date, MIN(date) OVER (PARTITION BY user_id) AS first_buy_date, LEAD(date) OVER (PARTITION BY user_id ORDER BY date) AS second_buy_date, COUNT(*) OVER (PARTITION BY user_id) AS cnt FROM order_info WHERE date>='2025-10-15' AND status='completed' AND product_name IN ('C++','Python','JAVA')) AS b1 WHERE b1.date=b1.first_buy_date AND b1.second_buy_date IS NOT NULL