temperaturdecke/queries01.sql

87 lines
2.5 KiB
MySQL
Raw Normal View History

2023-02-12 11:20:24 +01:00
-- vergleiche Tagesdurchschnitt und 12-Uhr-Durchschnitt
2023-02-12 11:18:35 +01:00
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;
2023-02-12 11:20:24 +01:00
-- zaehle Verteilung bei 12-Uhr-Durchschnitt
2023-02-12 11:18:35 +01:00
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
2023-02-12 22:38:49 +01:00
extract('year' from time) = 2022
2023-02-12 11:18:35 +01:00
group by day
order by day
)
select
temperature::numeric(10,0) as t,
count(*)
from
day_avg
group by t;
2023-02-12 11:22:19 +01:00
-- 12-Uhr-Werte
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;
2023-02-12 22:38:49 +01:00
-- Tageswert
select
extract('day' from time)::varchar || '.' || extract('month' from time)::varchar || '.' || extract('year' from time)::varchar 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
time::date = now()::date
group by day;