#第一,以三个条件剔除部分数据
#第二:上窗口函数
#第三:取出数据
SELECT * FROM order_info WHERE DATE > "2025-10-15" AND product_name IN ("C++","Java","Python") AND STATUS = "completed"
#第二:上窗口函数
SELECT *, dense_rank() over(PARTITION BY user_id ORDER BY DATE) "first_day", COUNT(user_id) over(PARTITION BY user_id ORDER BY user_id) "cnt" FROM (SELECT * FROM order_info WHERE DATE > "2025-10-15" AND product_name IN ("C++","Java","Python") AND STATUS = "completed" ) t
#第三:取出数据
SELECT user_id, `date` "first_buy_date", cnt FROM (SELECT *, dense_rank() over(PARTITION BY user_id ORDER BY DATE) "first_day", COUNT(user_id) over(PARTITION BY user_id ORDER BY user_id) "cnt" FROM (SELECT * FROM order_info WHERE DATE > "2025-10-15" AND product_name IN ("C++","Java","Python") AND STATUS = "completed" ) t) tt WHERE first_day = 1 AND cnt >= 2 ORDER BY user_id