Skip to content

Instantly share code, notes, and snippets.

@kidpixo
Created October 24, 2013 09:08
Show Gist options
  • Save kidpixo/7133792 to your computer and use it in GitHub Desktop.
Save kidpixo/7133792 to your computer and use it in GitHub Desktop.
amazza che mazzasql
WITH p AS (
SELECT *
FROM (SELECT array_agg(id_meas) AS arr_id_meas,id_poly FROM user_polygons_vertex_intersection GROUP BY id_poly ORDER BY COUNT(id_meas) ASC LIMIT 2 OFFSET 500) up_in
INNER JOIN user_polygons up ON up_in.id_poly=up.polygon_id
WHERE view_short_name='global_grid_1dpp'
)
SELECT COUNT(m.id_meas),p.id_poly,trim(first(p.polygon_name)) AS polygon_name,ST_AsText(first(p.polygon))
FROM vir_point_data m,p
WHERE m.id_meas = ANY (p.arr_id_meas)
GROUP BY p.id_poly;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment