Skip to content

Instantly share code, notes, and snippets.

View dpareek10's full-sized avatar

Deepali Pareek dpareek10

  • Cardlytics
  • Atlanta
View GitHub Profile
@stsibel
stsibel / MySQL_zipcodes_within_radius.sql
Last active September 26, 2022 18:02
MySQL query to find zip-codes within given radius from any point (or zip-code)
/* Given table 'zipcodes' with columns:
zipcode, latitude, longitude.
Find zipcodes within radius from given zipcode.
EXAMPLE:
Coordinates for zip 91326 and radius 25 mi:
*/
SET @location_lat = 34.2766,
@location_lon = -118.544;
SELECT zipcode, ( 3959 * acos( cos( radians(@location_lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(@location_lon) ) + sin( radians(@location_lat) ) * sin( radians( latitude ) ) ) ) AS distance