5
我想用多個條件更新多列。例如 如何在單個sql查詢中使用條件更新多列
update student set name='john' where id=10
update student set name='doe' where id=5
如何在單個語句中更新此內容?
我想用多個條件更新多列。例如 如何在單個sql查詢中使用條件更新多列
update student set name='john' where id=10
update student set name='doe' where id=5
如何在單個語句中更新此內容?
使用CASE WHEN
update student
set name= CASE WHEN id = 5 THEN 'john'
WHEN id = 10 THEN 'doe'
ELSE name
END
where id in (
5, 10
)
update tablename
set coloumn_name1= CASE WHEN coloumn_name = 5 THEN 'john'
WHEN coloumn_name = 10 THEN 'doe'
ELSE name
END
where coloumn_name in (
5, 10
)
入住此SO:http://stackoverflow.com/questions/13673890/mysql-case-to-update-multiple-columns –
另外,爲什麼你不介意做單獨的陳述? –