Last active
November 19, 2020 15:44
-
-
Save CarMoreno/9331ee4f74071bdfeaea06e7d4dc510e to your computer and use it in GitHub Desktop.
Unir tablas PIVOT eliminando duplicados - Bigquery
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
CREATE OR REPLACE TABLE `tabla_c` AS | |
( | |
WITH tabla_intermedia AS ( | |
SELECT * FROM `tabla_a` #Tabla Inicial | |
UNION DISTINCT | |
SELECT * FROM `tabla_2` #Tabla particionada 2 | |
) | |
SELECT row[OFFSET(0)].* FROM ( | |
SELECT ARRAY_AGG(t ORDER BY fecha_consulta DESC LIMIT 1) row | |
FROM tabla_intermedia t | |
GROUP BY id_interno | |
)ORDER BY id_interno | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment