Skip to content

Instantly share code, notes, and snippets.

@ramiroaznar
Created August 23, 2016 13:42
Show Gist options
  • Save ramiroaznar/e85e223ae31b34a56bb72616be6c5fc5 to your computer and use it in GitHub Desktop.
Save ramiroaznar/e85e223ae31b34a56bb72616be6c5fc5 to your computer and use it in GitHub Desktop.
Select and count points within a polygon
SELECT
pa.*,
array_to_string(array_agg(cp.cartodb_id), ', ') as ids,
count(cp.*) as count_clients
FROM
ramirocartodb.clients_points cp RIGHT JOIN ramirocartodb.protected_areas pa ON
ST_Intersects(cp.the_geom, pa.the_geom)
GROUP BY
pa.cartodb_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment