Sql 我不知道';我无法从查询中获得所需的结果
我有两个名为“District”和“SensorData”的表。从这两个表中,我想知道“SensorData”表中的哪些点位于“District”多边形内 我编写此查询是为了获得我想要的结果:Sql 我不知道';我无法从查询中获得所需的结果,sql,postgresql,postgis,Sql,Postgresql,Postgis,我有两个名为“District”和“SensorData”的表。从这两个表中,我想知道“SensorData”表中的哪些点位于“District”多边形内 我编写此查询是为了获得我想要的结果: SELECT combined_sensor_data.point_geom, district.geom_pol FROM combined_sensor_data, district WHERE ST_Within(district.geom_pol, combined_sensor_data.poi
SELECT combined_sensor_data.point_geom, district.geom_pol
FROM combined_sensor_data, district
WHERE ST_Within(district.geom_pol, combined_sensor_data.point_geom);
但不幸的是,我在任何地区都毫无意义。我确信这是一个错误的结果。所以我假设我的查询有错误。因此,我要问的是,我的查询中可能有什么错误?您可以尝试更改参数顺序:
SELECT combined_sensor_data.point_geom, district.geom_pol
FROM combined_sensor_data
JOIN district
ON ST_Within(combined_sensor_data.point_geom, district.geom_pol);
根据我对您问题的理解,您似乎想检查表2(“地区”)是否也有与表1(“传感器数据”)相同的数据点 您可以为此使用PostgreSQL EXISTS:
select combined_sensor_data.point_geom from combined_sensor_data sd
where exists (select 1 from district d where d.geom_pol=sd.point_geom)
尝试此查询。它会更改该点是包含在其他表中的任何多边形中,还是与多边形重叠。您可能需要更改GROUPBY子句
SELECT combined_sensor_data.point_geom, district.geom_pol
bool_or((ST_Contains(T2.geom_pol, T1.point_geom) OR ST_Overlaps(T1.point_geom,T2.geom_pol))) AS my_bool
FROM combined_sensor_data AS T1
CROSS JOIN district AS T2 WHERE my_bool is true
GROUP BY combined_sensor_data.point_geom, district.geom_pol
请显示少量与查询相关的数据-这将使其他人更容易提供解决方案。谢谢Lukasz,但它也不起作用。我怀疑当时的问题可能是我不知道会是什么:(所有的解决方案都有效,但问题出在其他地方,无论如何,谢谢!)