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 –
另外,为什么你不介意做单独的陈述? –