title: number of points within a radius of another set of points
body: <p>I have two tables. One is a list of stores (with lat/long). The other is a list of customer addresses (with lat/long). What I want is a query that will return the number of customers within a certain radius for each store in my table. This gives me the total number of customers within 10,000 meters of ANY store, but I'm not sure how to loop it to return one row for each store with a count.</p>
  
  <p>Note that I'm doing this queries using cartoDB, where <code>the_geom</code> is basically long/lat.</p>
  
  <pre><code>SELECT COUNT(*) as customer_count FROM customer_table 
  WHERE EXISTS(
      SELECT 1 FROM store_table
      WHERE ST_Distance_Sphere(store_table.the_geom, customer_table.the_geom) &lt; 10000
  )
  </code></pre>
  
  <p>This results in a single row :</p>
  
  <pre><code>customer_count
  4009
  </code></pre>
  
  <p>Suggestions on how to make this work against my problem? I'm open to doing this other ways that might be more efficient (faster).</p>
  
  <p>For reference, the column with store names, which would be in one column is <code>store_identifier.store_table</code></p>