输入banner图图片脚本导航/分类

mysql update中需要根据条件列更新写法update case

t9 set id=1 where b>2015-10-12; update t9 set id=1, e=2015-01-01 where b=2015-10-12;

 

既然来写博客了,那答案肯定是可以的,

如下写法可以就上面的两条update语句合并成一条:

update t9 set id=1, e=(case when b=2015-10-12 then 2015-01-01 else e end)   where   b>=2015-10-12; 

即:

当b等于2015-10-12时,e值设置为2015-01-01

当b大于2015-10-12时,e值保持不变。

 

这是一个小小技巧,有需要的朋友尽管拿去。

 

mysql update中需要根据条件列更新写法update case

标签: