From 0dd6410a64d55c4277e49e52a82b3a3ff73d748d Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sun, 12 Feb 2023 11:18:35 +0100 Subject: [PATCH] initial --- queries01.sql | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 queries01.sql diff --git a/queries01.sql b/queries01.sql new file mode 100644 index 0000000..5354cd0 --- /dev/null +++ b/queries01.sql @@ -0,0 +1,59 @@ +with + twelve_avg as ( + select + date_trunc('day', time)::date as day, + avg(temperature)::numeric(10,0) as temperature + from room_climate_measurement_t + where + category = 'Outdoor' and + location = 'Outdoor' and + extract('hour' from time) = 12 and + extract('year' from time) = 2023 + group by day + order by day + ), + day_avg as ( + select + date_trunc('day', time)::date as day, + avg(temperature)::numeric(10,0) as temperature + from room_climate_measurement_t + where + category = 'Outdoor' and + location = 'Outdoor' and + extract('year' from time) = 2023 + group by day + order by day + ) + select + d.day as day, + d.temperature as day_avg_temperature, + t.temperature as twelve_avg_temperature, + (d.temperature - t.temperature) as swing + from day_avg d, + twelve_avg t + where d.day = t.day; + + + +with + day_avg as ( + select + date_trunc('day', time)::date as day, + avg(temperature) as temperature + from room_climate_measurement_t + where + category = 'Outdoor' and + location = 'Outdoor' and + extract('hour' from time) = 12 and + extract('year' from time) = 2023 + group by day + order by day + ) + select + temperature::numeric(10,0) as t, + count(*) + from + day_avg + group by t; + +