Skip to content

Instantly share code, notes, and snippets.

@djouallah
Created January 26, 2021 22:11
Show Gist options
  • Save djouallah/936ead48525643b1abb334751526d3be to your computer and use it in GitHub Desktop.
Save djouallah/936ead48525643b1abb334751526d3be to your computer and use it in GitHub Desktop.
WITH
xx AS (
SELECT
"australia" AS key,
state,
suburbs,
longitude,
latitude,
IRSAD
FROM
`xxxxx.GIS.suburbs`)
SELECT
key,
xx.state,
xx.suburbs,
longitude,
latitude,
IRSAD,
100*ROUND(SQRT(POWER((lon2-longitude),2)+POWER((lat2-latitude),2)),2) AS dist,
IRSADREF
FROM
xx
LEFT JOIN (
SELECT
"australia" AS dummy,
state,
suburbs AS ref,
IRSAD AS IRSADREF,
longitude AS lon2,
latitude AS lat2
FROM
`xxxxx.GIS.suburbs`
WHERE
LOWER(suburbs) LIKE LOWER( @suburb )
LIMIT
1) ss
ON
xx.key= ss.dummy
WHERE
100*ROUND(SQRT(POWER((lon2-longitude),2)+POWER((lat2-latitude),2)),2) < @distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment