I have a three different tables:
Name1 | Geom |
---|---|
Name... | POLYGON.. |
Cell 3 | Cell 4 |
Name2 | Geom |
---|---|
Name... | POLYGON.. |
Cell 3 | Cell 4 |
ID | Num | Geom |
---|---|---|
ID... | 54 | POINT... |
Cell 3 | 33 |
I want to find where are polygons interesected and inside that area of intersection to sum points attribute - Num.
I tried this query:
SELECT sum(Num) as total, Polygons1.Name1
from Points,
Polygons1,
Polygons2
where ST_intersects(Polygons1.geom , Polygons2.geom)
GROUP BY Polygons1.Name1
This query returns some really big sum numbers that are not correct. Please help.
Points.Num
listed next to each Polygons1.Name1
that found a matching geom in Polygons2
. See this demo.SELECT sum(p.Num) as total,
Polygons1.Name1
from Polygons1 as plg1
join Polygons2 as plg2
on ST_Intersects(plg1.geom, plg2.geom)
join Points as p
on ST_Within(p.geom, ST_Intersection(plg1.geom, plg2.geom) )
GROUP BY Polygons1.Name1;
Make sure you're clear on what you mean by inside and intersection: