I'm trying to use CartoDB to Count all of the records a given distance from a selected location.
I have the lat/long for the selected location (call this a store). Now I need to find all of the records (representing customers) that are a given distance (say, 8046 meters/5 miles) from the selected location.
What SQL query should I be using? I've tried some basic things like this, but they didn't work:
'SELECT COUNT() from my_table_name WHERE the_geom && ST_SetSRID(ST_Point(39.8282, -98.5795), 8046)'
or this:
SELECT COUNT() from my_table_name WHERE ST_INTERSECTS(the_geom,CIRCLE(LATLNG(39.8282, -98.5795),8046))
What query do I actually need? All I want to do is count the records that meet this criteria. Step 2 would be to filter the points on the map to show only those that meet the criteria, but one thing at a time.
INNER JOIN
would be for me and how this would fit:SELECT roads.roadname, pois.poiname FROM roads INNER JOIN pois ON ST_DWithin(roads.geog, pois.geog, 1609);
SELECT * FROM my_table INNER JOIN my_table.id ON ST_DWithin(40.4000, -90.6833, 16090)
but there's a lot wrong with what I've got. Can't figure out what my equivalent is for "pois" and how the join should work given that I'm only querying one table, not two like this example.