Last active
May 16, 2022 06:42
-
-
Save garystafford/e05de9db6ae79617702e53ab9a314e71 to your computer and use it in GitHub Desktop.
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
WITH credit_demographics AS ( | |
SELECT | |
(year (now()) - c_birth_year) AS age, | |
cd_credit_rating AS credit_rating, | |
cd_gender AS gender, | |
count(cd_gender) AS gender_count | |
FROM | |
postgresql.public.customer | |
LEFT JOIN hive.default.customer_demographics ON c_current_cdemo_sk = cd_demo_sk | |
WHERE | |
c_birth_year IS NOT NULL | |
AND cd_credit_rating IS NOT NULL | |
AND lower(cd_credit_rating) != 'unknown' | |
AND cd_gender IS NOT NULL | |
GROUP BY | |
cd_credit_rating, | |
c_birth_year, | |
cd_gender | |
) | |
SELECT | |
age, | |
credit_rating, | |
gender, | |
gender_count | |
FROM | |
credit_demographics | |
WHERE | |
age BETWEEN 21 AND 65 | |
ORDER BY | |
age, | |
credit_rating, | |
gender; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks