我试图找出24小时内最大的温差,并返回产生温差所需的时间。下面的代码成功地找到了任何给定的24小时窗口中最高和最低温度的差异,但是,我还需要返回每个最高和最低温度的日期/时间信息,以便计算它们之间的时间量。
如何更改此查询以跟踪哪个日期/时间与行上的max(o.temp)over、min(o.temp)over关联?
SELECT
o.long_date as long_date
,MAX(o.temp) over (order by o.unix range between 86400 preceding and current row) as max_temp
,MIN(o.temp) over (order by o.unix range between 86400 preceding and current row) as min_temp
FROM
(
SELECT
unix_time AS unix
,date as long_date
,temp AS temp
FROM oshkosh
WHERE temp != -9999) as o
输出
o.unix long_date max_temp min_temp
946687980 2000-01-01 00:53:00 35.1 35.1
946691580 2000-01-01 01:53:00 35.1 35.1
946695180 2000-01-01 02:53:00 35.1 35.1
946698780 2000-01-01 03:53:00 34.0 34.0
946702380 2000-01-01 04:53:00 32.0 32.0
946705980 2000-01-01 05:53:00 30.9 30.9
946709580 2000-01-01 06:53:00 28.0 28.0
946713180 2000-01-01 07:53:00 28.0 28.0
946716780 2000-01-01 08:53:00 28.0 28.0
946720380 2000-01-01 09:53:00 33.1 33.1
946723980 2000-01-01 10:53:00 34.0 34.0
946727580 2000-01-01 11:53:00 36.0 36.0
946731180 2000-01-01 12:53:00 35.1 35.1
946734780 2000-01-01 13:53:00 34.0 34.0
946738380 2000-01-01 14:53:00 33.1 33.1
暂无答案!
目前还没有任何答案,快来回答吧!