I currently have a table containing raw temperature data that looks like this:
I have written a query to find the min, max and avg of this data grouped by the date of the timestamp:
drop table solardb.weatherinfodaily;
select date_trunc('day',ts) as ts,
min("Air Temperature (Actual) (Degrees C)")*9/5 + 32 as "Daily Min Temp (F)",
avg("Air Temperature (Actual) (Degrees C)")*9/5 + 32 as "Daily Avg Temp (F)",
max("Air Temperature (Actual) (Degrees C)")*9/5 + 32 as "Daily Max Temp (F)"
into solardb.weatherinfodaily
from solardb.weatherdata
group by date_trunc('day',ts)
order by date_trunc('day',ts);
select * from solardb.weatherinfodaily;
I would like to return the timestamp that is associated with the aggregate function and I have not figured out a way to do this yet.
i.e. the query would return:
ts, Daily Min Temp, timestamp from raw data table when the min temp happened, daily avg temp, daily max temp, timestamp from raw data when max temp happened.
How can I write such a query?
min()
,avg()
andmax()
values in the separate table?