这个很难解释,但基本上我想选择距离较小的条件。查询如下:
update point_a a
set c_id = (select b.otherid
from point_b b, line c
where a.pointid = c.lineconnecting_a_id
and (st_endpoint(c.geom) = b.geom or st_startpoint(c.geom) = b.geom order by distance limit 1
基本上在最后一行我想用这条线来选择它连接的点,我想要更接近原点的点。问题是,对于我的 OR,我得到 2 分,但我不知道如何限制才能使用 st_distance 并选择最接近的。
换句话说,对于每一行,我需要根据它们到原点的距离来选择起点或终点
最佳答案
请发布有效查询。和表定义。这也可能使您更容易理解您的问题
无论如何,如果我正确理解你的问题,这应该有效(未经测试)
update point_a a
set c_id = (
select otherid
from (
select b.otherid, distance
from point_b b, line c
where a.pointid = c.lineconnecting_a_id
and (st_endpoint(c.geom) = b.geom)
UNION
select b.otherid, distance
from point_b b, line c
where a.pointid = c.lineconnecting_a_id
and (st_startpoint(c.geom) = b.geom)
)
order by distance limit 1
);
关于sql - 如何在postgresql中的where条件的较低值之间进行选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47355554/