2012-11-06 70 views
0

我有兩個表都具有相同的列,但行數不同。將特定的一組行從一個表複製到另一個表

Generation 
{Date, 
location, 
location_id, 
turbine_id, 
Generation,} 

Generation_copy 
{date, 
location, 
location_id, 
turbine_id, 
Generation} 

在代表我有5000行具有行最新的,並且在Generation_copy我只有4500,我還沒有更新的表,最近1周

行現在我需要補未填充500行到表Generation_copy中。

+0

在這裏你需要同步這兩個表? – AnandPhadke

+0

是的,我需要更新generation_copy表,以便將來再添加兩列。 –

+0

生成表中是否有任何PK或唯一列? – solaimuruganv

回答

2
insert into generation_copy 
    select * from generation where (date,location) 
    not in 
(select date,location from generation_copy) 
+0

非常感謝sola!在更新我的數據庫中的其他表時,它會幫助我很多。 –

1

你試過這個嗎?

DELETE FROM Generation_copy;

- 然後只是重新複製值。

INSERT INTO Generation_copy(時間,地點,LOCATION_ID,turbine_id,代) 選擇日期,地點,LOCATION_ID,turbine_id,代代

+0

好吧,我會嘗試!!我已經分配了獨特的鍵合併日期和位置,所以當運行插入我有重複錯誤! !有沒有其他解決方案 –

相關問題