Last active
June 15, 2022 09:51
-
-
Save CassandraOfTroy/f3fb811cc171302194abc9916f933502 to your computer and use it in GitHub Desktop.
Joining input table and table with the missing values in our dataset
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 | |
table_a.ascending_date, | |
table_a.shop, | |
CASE WHEN | |
table_b.new_article_count IS null | |
THEN 0 | |
ELSE | |
table_b.new_article_count | |
END AS number_of_listed_articles | |
FROM | |
( | |
SELECT | |
CAST(day AS DATE) as ascending_date, | |
sb.shop as shop | |
FROM | |
(SELECT '3djake' as shop | |
UNION ALL SELECT 'geero') sb, | |
(SELECT | |
day | |
FROM | |
UNNEST( | |
GENERATE_DATE_ARRAY( | |
DATE('2021-01-01'), | |
CURRENT_DATE(), | |
INTERVAL 1 DAY | |
) | |
) AS day | |
) | |
) table_a | |
LEFT JOIN | |
(SELECT '3djake' as shop, 20 as new_article_count, DATE(2021, 01, 05) as article_online_since_date | |
UNION ALL SELECT '3djake', 10, DATE(2021, 01, 07) | |
UNION ALL SELECT '3djake', 5, DATE(2021, 01, 10) | |
UNION ALL SELECT '3djake', 8, DATE(2021, 01, 10) | |
UNION ALL SELECT '3djake', 5, DATE(2021, 01, 21) | |
UNION ALL SELECT '3djake', 15, DATE(2021, 01, 23) | |
UNION ALL SELECT 'geero', 12, DATE(2021, 01, 01) | |
UNION ALL SELECT 'geero', 2, DATE(2021, 01, 04) | |
UNION ALL SELECT 'geero', 5, DATE(2021, 01, 08) | |
UNION ALL SELECT 'geero', 1, DATE(2021, 01, 23) | |
UNION ALL SELECT 'geero', 4, DATE(2021, 01, 30) | |
) table_b | |
ON | |
table_a.shop = table_b.shop | |
AND | |
table_a.ascending_date = table_b.article_online_since_date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment