Skip to content

Instantly share code, notes, and snippets.

@donamkhanh
Created September 12, 2012 11:34
Show Gist options
  • Save donamkhanh/3706083 to your computer and use it in GitHub Desktop.
Save donamkhanh/3706083 to your computer and use it in GitHub Desktop.
SELECT DISTANCE
SELECT *
FROM (SELECT *,
((2 * 3960 *
ATAN2(
SQRT(
POWER(SIN((RADIANS(47.470779 - latitude))/2), 2) +
COS(RADIANS(latitude)) *
COS(RADIANS(47.470779 )) *
POWER(SIN((RADIANS(-87.890699 - longitude))/2), 2)
),
SQRT(1-(
POWER(SIN((RADIANS(47.470779 - latitude))/2), 2) +
COS(RADIANS(latitude)) *
COS(RADIANS(47.470779 )) *
POWER(SIN((RADIANS(-87.890699 - longitude))/2), 2)
))
)
) * 1.609344) AS distance
FROM zip_codes) as tmp_table
WHERE distance < 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment