MySQL字符串操作

【截取】

1.字段右侧截取
RIGHT(‘字段名’,长度);

SELECT RIGHT(user_affiliate,3) FROM usertable;

2.字段左侧截取
LEFT(‘字段名’,长度);

SELECT LEFT(user_affiliate,3) FROM usertable;

3.中间截取
substring(‘字段名’,开始位置,长度);

//  第一位从1开始
select substring(user_affiliate,6,3) from usertable;

【拼接】

CONCAT(字符串,字符串…);

SELECT CONCAT(RIGHT(user_affiliate,3),user_number) nam from usertable;

【更新】
update中使用select

UPDATE usertable  
inner join(SELECT CONCAT(RIGHT(user_affiliate,3),user_number) nam,user_id from usertable) c 
 on usertable.user_id = c.user_id set usertable.user_number = c.nam

猜你喜欢

转载自blog.csdn.net/weixin_42547014/article/details/109739045