I’m thinking the only way to do it is to sum the values between (today – 365) and (today -65 + 90) then move on by 1 day each time, but that would be impractical. Is there a way around it?
Advertisement
Answer
If you have one row on each day:
select top (1) t.* from (select t.*, sum(x) over (order by date rows between 89 preceding and current row) as sum_90 from t ) t order by sum_90 desc;