-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc1d2a4
commit 7e286d1
Showing
6 changed files
with
517 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
UPDATE | ||
{table_name} | ||
SET | ||
eolRecyclingPercent = updated.eolRecyclingPercent, | ||
eolIncinerationPercent = updated.eolIncinerationPercent, | ||
eolLandfillPercent = updated.eolLandfillPercent, | ||
eolMismanagedPercent = updated.eolMismanagedPercent | ||
FROM | ||
( | ||
SELECT | ||
year, | ||
region, | ||
eolRecyclingPercent / ( | ||
eolRecyclingPercent + | ||
eolIncinerationPercent + | ||
eolLandfillPercent + | ||
eolMismanagedPercent | ||
) AS eolRecyclingPercent, | ||
eolIncinerationPercent / ( | ||
eolRecyclingPercent + | ||
eolIncinerationPercent + | ||
eolLandfillPercent + | ||
eolMismanagedPercent | ||
) AS eolIncinerationPercent, | ||
eolLandfillPercent / ( | ||
eolRecyclingPercent + | ||
eolIncinerationPercent + | ||
eolLandfillPercent + | ||
eolMismanagedPercent | ||
) AS eolLandfillPercent, | ||
eolMismanagedPercent / ( | ||
eolRecyclingPercent + | ||
eolIncinerationPercent + | ||
eolLandfillPercent + | ||
eolMismanagedPercent | ||
) AS eolMismanagedPercent | ||
FROM | ||
{table_name} | ||
WHERE | ||
year > 2020 OR year < 2005 | ||
) updated | ||
WHERE | ||
updated.year = {table_name}.year | ||
AND updated.region = {table_name}.region |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
UPDATE | ||
{table_name} | ||
SET | ||
netImportArticlesMT = updated.netImportArticlesMT, | ||
netImportFibersMT = updated.netImportFibersMT, | ||
netImportGoodsMT = updated.netImportGoodsMT, | ||
netImportResinMT = updated.netImportResinMT | ||
FROM | ||
( | ||
SELECT | ||
{table_name}.year AS year, | ||
{table_name}.region AS region, | ||
( | ||
CASE | ||
WHEN totalArticlesMT > 0 AND netImportArticlesMT > 0 THEN netImportArticlesMT - totalArticlesMT * netImportArticlesMT / totalImportArticlesMTPos | ||
WHEN totalArticlesMT < 0 AND netImportArticlesMT < 0 THEN netImportArticlesMT - totalArticlesMT * netImportArticlesMT / totalImportArticlesMTNeg | ||
ELSE netImportArticlesMT | ||
END | ||
) AS netImportArticlesMT, | ||
( | ||
CASE | ||
WHEN totalFibersMT > 0 AND netImportFibersMT > 0 THEN netImportFibersMT - totalFibersMT * netImportFibersMT / totalImportFibersMTPos | ||
WHEN totalFibersMT < 0 AND netImportFibersMT < 0 THEN netImportFibersMT - totalFibersMT * netImportFibersMT / totalImportFibersMTNeg | ||
ELSE netImportFibersMT | ||
END | ||
) AS netImportFibersMT, | ||
( | ||
CASE | ||
WHEN totalGoodsMT > 0 AND netImportGoodsMT > 0 THEN netImportGoodsMT - totalGoodsMT * netImportGoodsMT / totalImportGoodsMTPos | ||
WHEN totalGoodsMT < 0 AND netImportGoodsMT < 0 THEN netImportGoodsMT - totalGoodsMT * netImportGoodsMT / totalImportGoodsMTNeg | ||
ELSE netImportGoodsMT | ||
END | ||
) AS netImportGoodsMT, | ||
( | ||
CASE | ||
WHEN totalResinMT > 0 AND netImportResinMT > 0 THEN netImportResinMT - totalResinMT * netImportResinMT / totalImportResinMTPos | ||
WHEN totalResinMT < 0 AND netImportResinMT < 0 THEN netImportResinMT - totalResinMT * netImportResinMT / totalImportResinMTNeg | ||
ELSE netImportResinMT | ||
END | ||
) AS netImportResinMT | ||
FROM | ||
{table_name} | ||
INNER JOIN | ||
( | ||
SELECT | ||
year, | ||
sum( | ||
CASE | ||
WHEN netImportArticlesMT > 0 THEN netImportArticlesMT | ||
ELSE 0 | ||
END | ||
) AS totalImportArticlesMTPos, | ||
sum( | ||
CASE | ||
WHEN netImportArticlesMT < 0 THEN netImportArticlesMT | ||
ELSE 0 | ||
END | ||
) AS totalImportArticlesMTNeg, | ||
sum( | ||
CASE | ||
WHEN netImportFibersMT > 0 THEN netImportFibersMT | ||
ELSE 0 | ||
END | ||
) AS totalImportFibersMTPos, | ||
sum( | ||
CASE | ||
WHEN netImportFibersMT < 0 THEN netImportFibersMT | ||
ELSE 0 | ||
END | ||
) AS totalImportFibersMTNeg, | ||
sum( | ||
CASE | ||
WHEN netImportGoodsMT > 0 THEN netImportGoodsMT | ||
ELSE 0 | ||
END | ||
) AS totalImportGoodsMTPos, | ||
sum( | ||
CASE | ||
WHEN netImportGoodsMT < 0 THEN netImportGoodsMT | ||
ELSE 0 | ||
END | ||
) AS totalImportGoodsMTNeg, | ||
sum( | ||
CASE | ||
WHEN netImportResinMT > 0 THEN netImportResinMT | ||
ELSE 0 | ||
END | ||
) AS totalImportResinMTPos, | ||
sum( | ||
CASE | ||
WHEN netImportResinMT < 0 THEN netImportResinMT | ||
ELSE 0 | ||
END | ||
) AS totalImportResinMTNeg, | ||
sum(netImportArticlesMT) AS totalArticlesMT, | ||
sum(netImportFibersMT) AS totalFibersMT, | ||
sum(netImportGoodsMT) AS totalGoodsMT, | ||
sum(netImportResinMT) AS totalResinMT | ||
FROM | ||
{table_name} | ||
GROUP BY | ||
year | ||
) totals | ||
ON | ||
{table_name}.year = totals.year | ||
WHERE | ||
{table_name}.year > 2020 OR {table_name}.year < 2005 | ||
) updated | ||
WHERE | ||
updated.year = {table_name}.year | ||
AND updated.region = {table_name}.region |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.