2013-01-14 85 views
1

我有這樣的:如何更新?

ID  ROW_A ROW_B 

'62919' | '9430' | '40754' 

我把它歸功於此查詢:

SELECT * FROM myTable 
WHERE ROW_A != 0 

我想更新它,把ROW_A的價值爲ROW_B

那麼,有沒有可能用一個查詢進行以下處理?現在

,我使用這個(但它是錯的):

UPDATE myTable SET ROW_B = ROW_A 
WHERE ID IN(
SELECT * FROM myTable 
WHERE ROW_A != 0) 
+0

你想讓ROW_A保持其價值,與B交換,還是什麼? – jeremyharris

+0

只需使用WHERE ROW_A!= 0''而不是整個'WHERE' – Turcia

+0

您是否想要交換列? – bonCodigo

回答

5

無需子查詢我會想:

UPDATE myTable 
SET  ROW_B = ROW_A 
WHERE ROW_A != 0 
2
UPDATE myTable 
SET ROW_B = ROW_A 
WHERE ROW_A != 0 
0

這可能會實現:

UPDATE myTable SET ROW_B = A 
WHERE ID IN(
SELECT ROW_A as A FROM myTable 
WHERE ROW_A !=0)