当前位置:Gxlcms > 数据库问题 > mysql update中需要根据条件列更新写法update case

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

时间:2021-07-01 10:21:17 帮助过:3人阅读

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

标签:

人气教程排行