sql update语句

1)常规的update语法:update 表名 set 字段名 = 值 where 条件

2)替换原有字段中的某个值:
需求:mit_ipran_config_items表有字段cmds,值为'...||undo dcn||...'   ,需要在||undo dcn前面加上||dcn

可以使用replace方法:replace(字段名,原有值,修改后的值)

update语法:update 表名 set 字段名 = replace(字段名,原有值,修改后的值) where id = xxx

这里是:update mit_ipran_config_items set cmds = replace(cmds,'||undo dcn','||dcn||undo dcn') where id = xxx

3)将原有字段值复制到指定字段中

需求:现有表mit_ipran_config_items,需要将id=1的字段cmds的值复制到id=2的cmds中

需要使用join,update语法:update 表名1 join 表名2 set 表名1.字段名 = 表名2.字段名 where 表名1.id = xxx

这里是: update mit_ipran_config_items as t1 join (select cmds from mit_ipran_config_items where id =1) as t2 set t1.cmds= t2.cmds where t1.id =2

4)使用update更新多个字段,set后面的字段逗号分隔

update 表名 set 字段名1 = 值, 字段名2 = 值 where 条件

5)in 集合:where 字段名 in (字段值1,字段值2,...)

如,修改多条记录的device_kind字段:UPDATE mit_ipran_config_items set device_kind = '950C' WHERE id in (8041,8042);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值