2013-03-01 128 views
2

我正在使用postgres,我有以下两个表。我想用来自altitude_of_point表的高度值更新distinct_network_point表,并将它们加入id值。从另一个表更新表

以下是distinct_network_point表:

enter image description here

以下是altitude_of_point表:

enter image description here

它是如何应SQL查询来完成这项工作的结构?

回答

2

我希望它能帮助:

UPDATE distinct_network_point 
SET altitude = altitude_of_point.altitude 
FROM altitude_of_point 
    WHERE distinct_network_point.id= altitude_of_point.id 
+0

以下错误POP操作起来:表名“distinct_network_point”指定多次 – 2013-03-01 11:13:45

+3

更多你并不需要包括表中进行更新FROM子句。事实上,这将创建一个你绝对不想要的笛卡尔连接。阅读手册 - 它明确涵盖了这一点。 – 2013-03-01 11:29:24

+0

@IT_info立即尝试。 – www 2013-03-01 11:31:11

0
UPDATE distinct_network_point 
SET altitude = altitude_of_point.altitude 
FROM distinct_network_point, altitude_of_point 
    WHERE distinct_network_point.id= altitude_of_point.id