Created
June 7, 2019 15:50
-
-
Save michimau/0838acd758eced9c2d23252314b043da to your computer and use it in GitHub Desktop.
This file contains hidden or 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
SELECT | |
source.year, | |
source.country_code, | |
source.pollutant_name, | |
source.sector_code, | |
source.emissions | |
FROM | |
clrtap_nec_unfccc.clrtap_nfr09_gf source, | |
( | |
SELECT | |
a.year, a.country_code, a.pollutant_name, | |
MAX(a.emissions) as emissions, | |
MIN(a.running_total) | |
from | |
clrtap_nec_unfccc.running_total_and_target a | |
WHERE | |
--a.pollutant_name = 'CO' AND | |
a.running_total >= a.target | |
GROUP BY a.year, a.country_code, a.pollutant_name | |
ORDER BY a.year, a.country_code, a.pollutant_name | |
) target | |
WHERE | |
source.year = target.year AND | |
source.country_code = target.country_code AND | |
source.pollutant_name = target.pollutant_name AND | |
source.emissions >= target.emissions AND | |
source.sector_code != 'NATIONAL TOTAL' | |
ORDER BY source.year, source.country_code, source.pollutant_name, source.emissions DESC, source.sector_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment