I have a table with 15min resolution in every 24 hour and looking to extract an hour with highest value which is sum of the highest four 15 minutes
I can find greatest value, but need to have four consecutive 15 minutes which give the highest hour in 24 hours
here is a sample data enter image description here
Four results from 19:30 to 20:15 will result in a maximum value and the one hour consist of these four 15 minutes provide max hour value
Updated 4/4/2023 added Result for each consecutive rows and at the end get the max
select
item
,max(sum)
from(
select
,result+lead(result),1,0) over (order by item,time)
+lead(result),2,0) over (order by item,time)
+lead(result),3,0) over (order by item,time) as sum
from db
)
where 1=1
and time >= current_date -2 and time < current_date -1
and item like ('item1')
group by 1
Above code gives me the max value looking for
Need help with
- Now I want to show other columns with the same max value