-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute.sql
81 lines (56 loc) · 1.4 KB
/
compute.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
Here we compute the production of biomethane by region
*/
CREATE OR REPLACE TABLE production_by_region AS
SELECT
NOM_REGION,
SUM(PRODUCTION_BIOMETHANE) AS PRODUCTION_BIOMETHANE_TOTAL
FROM
"PROJET_PERSO"."PUBLIC"."biomethane"
GROUP BY
NOM_REGION
ORDER BY
SUM(PRODUCTION_BIOMETHANE) DESC;
/*
Here we compute the production of biomethane by date
*/
CREATE OR REPLACE TABLE total_production_by_date AS
SELECT
DATE,
SUM(PRODUCTION_BIOMETHANE) AS PRODUCTION_BIOMETHANE_TOTAL
FROM
"PROJET_PERSO"."PUBLIC"."biomethane"
GROUP BY
DATE
ORDER BY
SUM(PRODUCTION_BIOMETHANE) DESC;
/*
Here we compute the production of biomethane by producer and by date
*/
CREATE OR REPLACE TABLE total_production_by_operator_and_date AS
SELECT
OPERATEUR_DE_TRANSPORT,
DATE,
SUM(PRODUCTION_BIOMETHANE) AS PRODUCTION_BIOMETHANE_TOTAL
FROM
"PROJET_PERSO"."PUBLIC"."biomethane"
GROUP BY
OPERATEUR_DE_TRANSPORT,
DATE
ORDER BY
SUM(PRODUCTION_BIOMETHANE) DESC;
/*
Here we compute a windows functions that make a classement of the region by date
*/
CREATE VIEW classement_region_by_dates AS
SELECT
NOM_REGION,
date,
SUM(PRODUCTION_BIOMETHANE) AS Total_Production,
RANK() OVER(PARTITION BY date ORDER BY SUM(PRODUCTION_BIOMETHANE) DESC) AS Rank
FROM
"PROJET_PERSO"."PUBLIC"."biomethane"
GROUP BY
NOM_REGION, date
ORDER BY
date;