两个开窗函数,一个求最小日期,一个求数量,然后你会发现重复了,所以加个distinct
select p.* from (
select DISTINCT user_id,min(date) over(partition by user_id order by date asc) as first_buy_date
,count(*) over(partition by user_id) as cnt
from order_info
where status='completed' and date>'2025-10-15'
and product_name in ('C++','Java','Python')
) p
where p.cnt>1
order by p.user_id asc



京公网安备 11010502036488号