Last active
September 19, 2023 20:37
-
-
Save nanoman657/c2d7db0210df198190e14ec60e49fe3d to your computer and use it in GitHub Desktop.
BigQuery Deduplication Extra Credit
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 | |
raw_person AS ( | |
SELECT | |
1 AS id, | |
'Joshua' AS first_name, | |
'Trusty' AS last_name, | |
'red' AS favorite_color, | |
'09-14-2023' AS date | |
UNION ALL | |
SELECT | |
1, | |
'Joshua', | |
'Trusty', | |
'scarlet', | |
'01-01-2023' | |
UNION ALL | |
SELECT | |
2, | |
'Misael', | |
'Gonzelez', | |
'red', | |
'09-14-2023' ), | |
person AS ( | |
SELECT | |
GENERATE_UUID() AS uuid, | |
* | |
FROM ( | |
SELECT | |
*, | |
ROW_NUMBER() OVER(PARTITION BY first_name, last_name ORDER BY date DESC) AS row_num | |
FROM | |
raw_person ) | |
WHERE | |
row_num = 1 ) | |
SELECT | |
* EXCEPT(row_num) | |
FROM | |
person |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment