I'm working on getting an interval min and max timestamp (15 second interval) where there is a peak interval value. In some cases there are 2 or more peak intervals, but in that case I only want the first interval values. The problem is when I do the max for interval_end it gives me the timestamp of the latest interval, which is incorrect. Please see screenshot below.
The min value of interval will be fine (2023-02-03 15:59:32.975), but the max interval value needs to be 2023-02-03 15:59:47.975). I now get the value of 2023-02-03 16:00:17.976, which is wrong.
The code I have is the following:
select day,
interval_start,
interval_end,
peak_msgrate_incoming,
max_peak_incoming_msgrate,
min(if(peak_msgrate_incoming = max_peak_incoming_msgrate, interval_start, null)) as interval_start_peak_in,
max(if(peak_msgrate_incoming = max_peak_incoming_msgrate, interval_end, null)) as interval_end_peak_out
from table
group by etc..
Can somebody help to get the "first max value" before seeing a null?
Expected output:
Thanks!