Created
July 25, 2020 21:15
-
-
Save yvanzo/ed95a564f0590d838803c04133753b19 to your computer and use it in GitHub Desktop.
Get country code (US) for Chicago (5099)
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
WITH RECURSIVE area_descendants AS ( | |
SELECT entity0 AS parent, entity1 AS descendant, 1 AS depth | |
FROM l_area_area laa | |
JOIN link ON laa.link = link.id | |
WHERE link.link_type = 356 | |
AND entity1 = 5099 | |
UNION | |
SELECT entity0 AS parent, descendant, (depth + 1) AS depth | |
FROM l_area_area laa | |
JOIN link ON laa.link = link.id | |
JOIN area_descendants ON area_descendants.parent = laa.entity1 | |
WHERE link.link_type = 356 | |
AND entity0 != descendant | |
) | |
SELECT iso.code | |
FROM area_descendants ad | |
JOIN iso_3166_1 iso ON iso.area = ad.parent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment