Created
March 21, 2018 17:59
-
-
Save hopeseekr/af38375aaeee63e80253b9a119359467 to your computer and use it in GitHub Desktop.
lab optimization
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
SET @dist = 20; | |
SET @latDist = @dist / 69.172; | |
SELECT zip_codes.* | |
FROM labs | |
JOIN zip_codes ON zip_codes.zip_code=labs.zip_code COLLATE utf8_unicode_ci | |
WHERE zip_codes.zip_code BETWEEN 70000 AND 79999 | |
AND labs.latitude < zip_codes.latitude + @latDist | |
AND labs.latitude > zip_codes.latitude - @latDist | |
AND SQRT( | |
POW(69.1 * (labs.latitude - zip_codes.latitude), 2) + | |
POW(69.1 * (zip_codes.longitude - labs.longitude) * COS(labs.latitude / 57.3), 2) | |
) <= @dist; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment