是不是这个意思 With base as ( Select id, price, date lag(price)over(partition by id order by price) as prcie1, lag(date)over(partition by id order by date) as date1 From a ) Select id,max(case when price>prcie1 then datediff(date,date2) then 0 end) From base Group by id