select user_id,first_buy_date,cnt
from
(select user_id,count(user_id) cnt,min(date) first_buy_date
from order_info
where date>'2025-10-15' and status='completed' and product_name in ('C++','Python','Java')
group by user_id) t
where t.cnt>=2
order by user_id思路:条件比较多,细心理清就好了,此题如果不用子查询也可以用group by + having 来做

京公网安备 11010502036488号