python

Mysql根据字段a的不同值,更新字段b为不同值_小皮de梦想的博客-CSDN博客

文章暂存

systemime
2021-05-18
1 min

摘要.

使用 case when:

UPDATE cp_system_param SET `value`=CASE WHEN cp_system_param.`code`='system_name' THEN 'aa' WHEN cp_system_param.`code`='system_title' THEN 'bb' WHEN cp_system_param.`code`='web_flg' THEN 'cc' ELSE `value` END```

注意:这里SQL如果不加  ELSE      END会导致别的字段值为空:

![](https://img-blog.csdn.net/20180704164707330?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjQ0NzM3Mw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)

![](https://img-blog.csdn.net/20180704160225946?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjQ0NzM3Mw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70) 
 [https://blog.csdn.net/weixin_42447373/article/details/80914203](https://blog.csdn.net/weixin_42447373/article/details/80914203) 
 [https://blog.csdn.net/weixin_42447373/article/details/80914203](https://blog.csdn.net/weixin_42447373/article/details/80914203)
上次编辑于: 5/20/2021, 7:26:49 AM