我需要編寫一個幫助我清理下表的更新查詢的幫助。我一直在手動做每一行,這只是漫長而疲憊的過程。一次更新多行的SQL查詢
有沒有辦法編寫一次更新整個表的更新查詢。
The rules:
1. All fields ending with m1 should only contain a value of 'aprn'
2. All fields ending with m2 should only contain a value of 'pa'
3. If 'pa' does exist in a field ending with m1 then that means that field should be NULL and the value 'pa' should be moved to the m2 column.
table_a
org_id org_name a_m1 a_m2 b_m1 b_m2
1 north aprn pa aprn pa
2 south null null pa null
3 east pa null pa null
4 west null pa null pa
Correct: ORG_ID=1 (a_m1, a_m2, b_m1, b_m2)
Correct: ORG_ID=4 (a_m1, a_m2, b_m1, b_m2)
Correct: ORG_ID=2 (a_m1, a_m2)
Incorrect: ORG_ID=2 (b_m1, b_m2)
Incorrect: ORG_ID=3 (a_m1, a_m2, b_m1, b_m2)
感謝...我認爲這是有幫助的。 – user1991499 2013-04-21 15:50:36
不客氣,@ user1991499。如果您發現有幫助的答案,請考慮提升和/或將其設置爲接受的答案。 – 2013-04-21 18:24:46