-
Notifications
You must be signed in to change notification settings - Fork 2
/
duckdb.sql
54 lines (48 loc) · 1.21 KB
/
duckdb.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- create some helpful views
create view sunpower_hourly as
select
ts,
year(ts) as year,
month(ts) as month,
day(ts) as day,
production,
consumption,
grid
from sunpower;
create view sunpower_daily as
select
date_trunc('day', ts) as day,
sum(production) as production,
sum(consumption) as consumption,
sum(grid) as grid
from sunpower
group by day;
create view sunpower_monthly as
select
date_trunc('month', ts) as month,
sum(production) as production,
sum(consumption) as consumption,
sum(grid) as grid
from sunpower
group by month;
create view sunpower_yearly as
select
date_trunc('year', ts) as year,
sum(production) as production,
sum(consumption) as consumption,
sum(grid) as grid
from sunpower
group by year;
-- output aggregates to csvs
copy (select * from sunpower_daily) to './data/aggregates/daily.csv';
copy (select * from sunpower_monthly) to './data/aggregates/monthly.csv';
copy (select * from sunpower_yearly) to './data/aggregates/yearly.csv';
-- daily avg per month
select
month(day),
avg(production) production,
avg(consumption) consumption,
avg(grid) grid
from sunpower_daily
group by month(day)
order by grid;