Skip to content

Commit

Permalink
Summarize over polymers for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
sampottinger authored Aug 3, 2023
1 parent 539c8db commit 9ae0565
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions sql/02_clean_inputs.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
CREATE VIEW consumption_raw AS
CREATE ROLE leo NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN NOREPLICATION NOBYPASSRLS PASSWORD 'bbv7of1v44';
GRANT SELECT ON TABLE public.label_tillage TO leo;
GRANT SELECT ON TABLE public.label_vpd TO leo;
GRANT SELECT ON TABLE public.raw_location TO leo;
GRANT SELECT ON TABLE public.raw_rci TO leo;
GRANT SELECT ON TABLE public.raw_tillage TO leo;
GRANT SELECT ON TABLE public.join_preview TO leo;
GRANT SELECT ON TABLE public.transform_rci TO leo;
GRANT SELECT ON TABLE public.transform_tillage TO leo;CREATE VIEW consumption_raw AS
SELECT
year AS year,
region AS region,
Expand Down Expand Up @@ -29,25 +37,37 @@ FROM

CREATE VIEW consumption_raw_pre_total AS
SELECT
year AS year,
region AS region,
summarized.year AS year,
summarized.region AS region,
(
CASE
WHEN majorMarketSector = 'textiles' THEN 'textile'
ELSE majorMarketSector
WHEN summarized.majorMarketSector = 'textiles' THEN 'textile'
ELSE summarized.majorMarketSector
END
) AS majorMarketSector,
consumptionMT AS consumptionMT
summarized.consumptionMT AS consumptionMT
FROM
(
SELECT
CAST(YEAR AS INTEGER) AS year,
lower(Region) AS region,
lower(Major_Market_Sector) AS majorMarketSector,
CAST(PC_Sector AS REAL) AS consumptionMT
interpreted.year AS year,
interpreted.region AS region,
interpreted.majorMarketSector AS majorMarketSector,
sum(consumptionMT) AS consumptionMT
FROM
file_consumption
);
(
SELECT
CAST(YEAR AS INTEGER) AS year,
lower(Region) AS region,
lower(Major_Market_Sector) AS majorMarketSector,
CAST(PC_Polymer AS REAL) AS consumptionMT
FROM
file_consumption
) interpreted
GROUP BY
interpreted.year,
interpreted.region,
interpreted.majorMarketSector
) summarized ;

CREATE VIEW eol_raw AS
SELECT
Expand Down

0 comments on commit 9ae0565

Please sign in to comment.