我有两个名为MAIN_WAYS和SUB_WAYS的表。
MAIN_WAYS (id, producer, geoemtry, length, size, ...)
SUB_WAYS (id, producer, geometry, ...)
所以我想更新SUB_WAYS生产者列,该列与MAIN_WAYS生产者列相同,接触到几何。 我可以将这两个表加入sql select。
select
sw.id sw_id,
sw.producer sh_producer,
mw.id mw_id, mw.producer mw_producer
from
sub_ways sw,
main_ways mw
where
st_touches(mw.geometry, sw.geoemtry);
还有
sw_id sh_producer mw_id mw_producer
1 null 1 x
2 null 2 x
3 null 3 y
4 null 5 z
一种主要方式可能涉及多种子方式。在这种情况下,所有触及一个地铁的地铁都将是同一生产者。
update
sub_ways
set
producer = mw.producer
from
sub_ways sw
inner join
main_ways mw on st_touches(mw.geometries, sw.geoemtry)
where
st_touches(mw.geometries, sw.geoemtry) and
sw.producer is null;
此查询将所有子路生产者设置为相同的值。
如何更新?
答案 0 :(得分:0)
您尚未将更新表与结果(from子句)连接在一起,因此它已更新为set from子句的最后一条记录中的值。
update
sub_ways sw
set
producer = mw.producer
from
main_ways mw
where
st_touches(mw.geometries, sw.geoemtry) and
sw.producer is null;