如何从其他表中获取匹配的数据?

时间:2016-08-08 09:37:29

标签: postgresql postgis

使用Postgres,我有2个表:

  • 第一个带有列sid,代理和邮政编码的区域。

  • 第二个名为postcodes,包含列id,邮政编码和几何图形。

如何将表格邮政编码中的几何列数据放入具有匹配邮政编码的表区域?

1 个答案:

答案 0 :(得分:3)

在查询中:

select t.*, p.geometry
  from territories as t left join postcodes p on t.postcode=p.postcode

只有在邮政编码表中没有重复的邮政编码时,这才有效。

如果要更新表区域,请首先添加该列,然后更新它:

update territories t set geometry = p.geometry
  from postcodes p
  where t.postcode=p.postcode
相关问题