【发布时间】:2016-12-09 14:07:43
【问题描述】:
我有一个失败的 SQL 查询,给我一个错误:
“有一个表条目,但不能从这部分查询中引用”
通过查询,我需要所有 3 个表,但只有trips 和boats 具有匹配的ID 才能加入。测试是一个 shapefile,我需要对其执行 postGIS 功能,但它与其他两个没有相似的列 ID。
select trips.*
from trips, test
inner join boats on boats.id = trips.boat_id
where st_intersects(trips.geom, test.geom) and
boats.uid = 44
我认为它与 join 语句有关,但我不太明白是什么。我对这里发生的事情的解释非常感兴趣。
【问题讨论】:
-
澄清一下——你是不是有意交叉加入
trips和test? -
不要混合隐式和显式连接,也不要在
from子句中添加逗号。 -
用更传统的方式可能是
... from trips join test on (st_intersects(trips.geom, test.geom)) join boats on (boats.id = trips.boat_id) where boats.uid = 44; -
@Abelisto,谢谢。你能解释一下为什么吗?
标签: sql postgresql postgis