I have a three different tables:
- Polygons1
| Name1 | Geom |
| ------------ | ------------ |
| Name... | POLYGON.. |
| Cell 3 | Cell 4 | - Polygons2
| Name2 | Geom |
| ------------ | ------------ |
| Name... | POLYGON.. |
| Cell 3 | Cell 4 | - Points
| 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.
1条答案
按热度按时间bmp9r5qi1#
1.除非在创建关系名时用双引号引起来,否则它们实际上是小写的。Make sure you know how you name things.有些工具会自动引用,有些工具不会。
1.你指定了如何配对多边形,但没有指定如何将点与这些多边形对匹配--在这种情况下,postgres假设你想将所有点与每对多边形连接起来,你可能会看到在
Polygons2
中找到匹配几何体的每个Polygons1.Name1
旁边列出的所有Points.Num
的重复总和,参见this demo。1.您使用了隐式联接。join your tables explicitly可能更容易。
确保您是clear on what you mean by inside and intersection: