2013-03-01 91 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