Skip to content

Instantly share code, notes, and snippets.

@Anticom
Created July 31, 2014 15:09
Show Gist options
  • Save Anticom/36ba9e0e488d20ed5955 to your computer and use it in GitHub Desktop.
Save Anticom/36ba9e0e488d20ed5955 to your computer and use it in GitHub Desktop.
location based search
SELECT
dest.sn,
dest.ort,
dest.kreis,
ACOS(
SIN(RADIANS(src.lat)) * SIN(RADIANS(dest.lat))
+ COS(RADIANS(src.lat)) * COS(RADIANS(dest.lat))
* COS(RADIANS(src.lon) - RADIANS(dest.lon))
) * 6380 AS distance
FROM
opengeodb dest
CROSS JOIN
opengeodb src
WHERE
src.sn= 3541
AND dest.sn <> src.sn
HAVING distance < 10
ORDER BY distance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment