我需要帮助编写一个更新查询来帮助我清理下表。我一直在手动完成每一行,这只是一个漫长而疲惫的过程。
有没有办法编写一次更新整个表的更新查询。
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)