SELECT oi.user_id, min(oi.date), x.cnt FROM order_info oi LEFT JOIN (select user_id, COUNT(id) as cnt from order_info where datediff(date,"2025-10-15")>0 and status ="completed" and product_name in("C++","Java","Python") group by user_id having count(id)>=2)x ON x.user_id = oi.user_id where datediff(oi.date,"2025-10-15")>0 and oi.status ="completed" and oi.product_name in("C++","Java","Python") and x.cnt is NOT NULL group by oi.user_id,x.cnt ORDER BY oi.user_id
这个方式比刚刚更简洁一些