SELECT m.content,o.order_price,o.id,m.id
FROM scp_home_msg m
INNER JOIN scp_order o ON m.link_id=o.id

把content  里面的金额换成order_price

1、获取金额

SELECT substring_index(content,'实付¥',-1)  FROM  scp_home_msg WHERE id=1096;
-- 1000.00"}

2、获取最后两个字符

SELECT right(substring_index(content,'实付¥',-1),2)  FROM  scp_home_msg WHERE id=1096;
-- "}

3、获取完整金额

SELECT substring_index(substring_index(content,'实付¥',-1),right(substring_index(content,'实付¥',-1),2),1)  FROM  scp_home_msg WHERE id=1096;
-- 1000.00

4、得到结果

SELECT substring_index(substring_index(content,'实付¥',-1),right(substring_index(content,'实付¥',-1),2),1) jieGuo,
m.content content,o.order_price orderPrice,o.id orderId,m.id mId
FROM scp_home_msg m
INNER JOIN scp_order o ON m.link_id=o.id;

5、获取金额不一致的数据 进行比较

SELECT STRCMP(substring_index(substring_index(m.content,'实付¥',-1),right(substring_index(m.content,'实付¥',-1),2),1),o.order_price) jieGuo,
substring_index(substring_index(content,'实付¥',-1),right(substring_index(content,'实付¥',-1),2),1) jj,
o.order_price orderPrice,m.content content,o.id orderId,m.id mId
FROM scp_home_msg m
INNER JOIN scp_order o ON m.link_id=o.id;

6、得到结果不同数据

SELECT STRCMP(substring_index(substring_index(m.content,'实付¥',-1),right(substring_index(m.content,'实付¥',-1),2),1),o.order_price) jieGuo,
substring_index(substring_index(content,'实付¥',-1),right(substring_index(content,'实付¥',-1),2),1) jj,
o.order_price orderPrice,m.content content,o.id orderId,m.id mId
FROM scp_home_msg m
INNER JOIN scp_order o ON m.link_id=o.id
WHERE STRCMP(substring_index(substring_index(m.content,'实付¥',-1),right(substring_index(m.content,'实付¥',-1),2),1),o.order_price) <> 0;

7、替换数据

SELECT m.content AS 替换前,REPLACE(content,substring_index(substring_index(content,'实付¥',-1),right(substring_index(content,'实付¥',-1),2),1),o.order_price) as 替换后,
o.order_price as 实付金额,substring_index(substring_index(content,'实付¥',-1),right(substring_index(content,'实付¥',-1),2),1) as 显示金额,
o.id orderId,m.id mId
FROM scp_home_msg m
INNER JOIN scp_order o ON m.link_id=o.id
WHERE substring_index(substring_index(m.content,'实付¥',-1),right(substring_index(m.content,'实付¥',-1),2),1) <> o.order_price;

总结:

1、replace(object, search,replace)
把object中出现search的全部替换为replace,select replace('www.163.com','w','Ww')--->WwW wWw.163.com
例:把表table中的name字段中的 aa替换为bb,update table set name=replace(name,'aa','bb')

来自:http://www.jb51.net/article/25769.htm

2、mysql字符串截取 来自:https://www.cnblogs.com/shuaiandjun/p/7197450.html?utm_source=itdadao&utm_medium=referral

1、left(str,index) 从左边第index开始截取

2、right(str,index)从右边第index开始截取

3、substring(str,index)当index>0从左边开始截取直到结束  当index<0从右边开始截取直到结束  当index=0返回空

4、substring(str,index,len) 截取str,从index开始,截取len长度

5、substring_index(str,delim,count),str是要截取的字符串,delim是截取的字段 count是从哪里开始截取(为0则是左边第0个开始,1位左边开始第一个选取左边的,-1从右边第一个开始选取右边的

6、subdate(date,day)截取时间,时间减去后面的day

7、subtime(expr1,expr2)  时分秒expr1-expr2

mysql 截取替换某个字符串的更多相关文章

  1. Mysql截取和拆分字符串函数用法

    Mysql截取和拆分字符串函数用法 截取字符串函数: SUBSTRING(commentid,9) 意思是:从第9个字符开始截取到最后.SUBSTRING的参数有三个,最后一个是截取的长度,默认是到结 ...

  2. mysql批量替换指定字符串

    将字段title中的abc替换为123 UPDATE `table1` SET `title` = replace(title, 'abc', '123') WHERE `typeid` =18;

  3. mysql 字符串 拼接 截取 替换

    一. 字符串拼接 concat('asdf',str); 说明: 拼接asdf 和 str 二. 字符串截取 从左开始截取字符串 left(str, length) 说明:) as abstract ...

  4. [转]Python 字符串操作实现代码(截取/替换/查找/分割)

    原文地址:http://www.jb51.net/article/38102.htm ps:好久没更新python代码了,这次用到了字符串,转来看看 Python 截取字符串使用 变量[头下标:尾下标 ...

  5. replace() MySQL批量替换指定字段字符串

    mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...

  6. Python 字符串操作(截取/替换/查找/分割)

    Python 截取字符串使用 变量[头下标:尾下标],就可以截取相应的字符串,其中下标是从0开始算起,可以是正数或负数,下标可以为空表示取到头或尾. # 例1:字符串截取 str = '1234567 ...

  7. mysql函数之七:replace() MySQL批量替换指定字段字符串

    mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...

  8. String字符串操作--切割,截取,替换,查找,比较,去空格.....

    字符串拼接 直接用+号:String a = "I"; String b = "love"; String c = "you";String ...

  9. mysql 截取字符串 函数

    文章摘取自http://www.cnblogs.com/zdz8207/p/3765073.html 练习截取字符串函数(五个) mysql索引从1开始 一.mysql截取字符串函数 1.left(s ...

随机推荐

  1. python2和python3关于列表推导的差别

    看下面两个例子: python2的环境:列表中的同名变量名被替换了 >>> x = 'my precious' >>> dummy = [x for x in 'A ...

  2. docker swarm 集群及可视化界面的安装及配置

    docker swarm 集群及可视化界面的安装及配置 2016-12-14 16:08:46 标签:swarm consul registrator 原创作品,允许转载,转载时请务必以超链接形式标明 ...

  3. Earth Wind 一个查看全球风向的网站

    可以查看整个地球的全貌 ,还能定位你的位置,特别是动画挺有意思 网址:https://earth.nullschool.net/#current/wind/surface/level/orthogra ...

  4. Tomcat 配置MySQL连接池

    <!--配置mysql数据库的连接池,         需要做的额外步骤是将mysql的Java驱动类放到tomcat的lib目录下                maxIdle 连接池中最多可 ...

  5. 获取select下拉框选中的的值

    有一id=test的下拉框,怎么获取选中的那个值呢? 分别使用javascript方法和jquery方法 <select id="test"  name="&quo ...

  6. Leetcode1000 合并石头的最低成本 区间DP

    有 N 堆石头排成一排,第 i 堆中有 stones[i] 块石头. 每次移动(move)需要将连续的 K 堆石头合并为一堆,而这个移动的成本为这 K 堆石头的总数. 找出把所有石头合并成一堆的最低成 ...

  7. Python学习笔记1环境搭建

    1.在浏览器输入https://www.python.org/psf/,点击download下载python3.7.2(https://www.python.org/)   https://www.p ...

  8. Hillstone设备管理-设备软件Stone-OS升级

    1.通过sysloader进行StoneOS升级 1)给设备上电按提示按ESC并且进入 Sysloader.参照以下操作提示: 2)在下面选择对应的选项升级os,可以通过tftp.ftp.usb.系统 ...

  9. JMeter 通过JSON Extractor 插件来提取响应结果

    接口响应结果,通常为HTML.JSON格式的数据,对于HTML的响应结果的提取,可以通过正则表达式,也可以通过XPath 来提取. 对于JSON格式的数据,可以通过正则表达式.JSON Extract ...

  10. Android面试准备20190422

    1.即时推送原理,采用的push推送模式,保持一个长连接,服务端和客户端连接后不再断开.所谓长连接,即是在一个TCP上可以连续发送多个数据包,在TCP连接保持期间,如果没有数据包发送,需要双方发送检测 ...