Mysql 一张表中某一列多条记录更新为不同的值,效率比较高

来源:互联网 发布:房屋立体设计软件 编辑:程序博客网 时间:2024/05/21 09:01

update 表名 set 列名= case when id= XX then  本列新记录when id= XX  then 本列新记录else 列名 end


将students表中number为1和2 的同学的姓名改为徐大咖和数数(number为主键)注:else后不加name列名会把出学号为1和2的其他记录的name值变为空

eg:update students set name= case when number='1' then '徐大咖' when id='2' then '数数' else name end;

0 0
原创粉丝点击