Created
October 23, 2012 22:26
-
-
Save zuckercode/3942110 to your computer and use it in GitHub Desktop.
opengeodb select
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
/* select one test zip */ | |
SELECT zc_id, zc_location_name, zc_lat, zc_lon | |
FROM zip_coordinates | |
WHERE zc_zip = '13187'; | |
/* calculate with the found data from above the zip in the radius < 20km */ | |
SELECT | |
zc_zip, | |
zc_location_name, | |
ACOS( | |
SIN(RADIANS(zc_lat)) * SIN(RADIANS(52.5710506114498)) | |
+ COS(RADIANS(zc_lat)) * COS(RADIANS(52.5710506114498)) * COS(RADIANS(zc_lon) | |
- RADIANS(13.4049687142945)) | |
) * 6380 AS distance | |
FROM zip_coordinates | |
WHERE ACOS( | |
SIN(RADIANS(zc_lat)) * SIN(RADIANS(52.5710506114498)) | |
+ COS(RADIANS(zc_lat)) * COS(RADIANS(52.5710506114498)) * COS(RADIANS(zc_lon) | |
- RADIANS(13.4049687142945)) | |
) * 6380 < 20 | |
AND zc_id <> 9739 | |
ORDER BY distance,zc_zip; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment