mysql 截取替换某个字符串
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 截取替换某个字符串的更多相关文章
- Mysql截取和拆分字符串函数用法
Mysql截取和拆分字符串函数用法 截取字符串函数: SUBSTRING(commentid,9) 意思是:从第9个字符开始截取到最后.SUBSTRING的参数有三个,最后一个是截取的长度,默认是到结 ...
- mysql批量替换指定字符串
将字段title中的abc替换为123 UPDATE `table1` SET `title` = replace(title, 'abc', '123') WHERE `typeid` =18;
- mysql 字符串 拼接 截取 替换
一. 字符串拼接 concat('asdf',str); 说明: 拼接asdf 和 str 二. 字符串截取 从左开始截取字符串 left(str, length) 说明:) as abstract ...
- [转]Python 字符串操作实现代码(截取/替换/查找/分割)
原文地址:http://www.jb51.net/article/38102.htm ps:好久没更新python代码了,这次用到了字符串,转来看看 Python 截取字符串使用 变量[头下标:尾下标 ...
- replace() MySQL批量替换指定字段字符串
mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...
- Python 字符串操作(截取/替换/查找/分割)
Python 截取字符串使用 变量[头下标:尾下标],就可以截取相应的字符串,其中下标是从0开始算起,可以是正数或负数,下标可以为空表示取到头或尾. # 例1:字符串截取 str = '1234567 ...
- mysql函数之七:replace() MySQL批量替换指定字段字符串
mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...
- String字符串操作--切割,截取,替换,查找,比较,去空格.....
字符串拼接 直接用+号:String a = "I"; String b = "love"; String c = "you";String ...
- mysql 截取字符串 函数
文章摘取自http://www.cnblogs.com/zdz8207/p/3765073.html 练习截取字符串函数(五个) mysql索引从1开始 一.mysql截取字符串函数 1.left(s ...
随机推荐
- Linux网络编程学习(十一) ----- 五种I/O模式(第六章)
1.五种I/O模式是哪几个? 阻塞I/O,非阻塞I/O,I/O多路复用,信号驱动I/O(SIGIO),异步I/O 一般来讲程序进行输入操作有两个步骤,一是等待有数据可读,二是将数据从系统内核中拷贝到程 ...
- 求$N^N$的首位数字
正如"大得多"定理所言,当$n\longrightarrow \infty$时: $$ n^n \gg n! \gg a^n \gg n^b \gg ln^kn $$ $f(n) = n^n$的增长 ...
- mysql学习二、SQL常用数据类型
一.常用数据类型 二.选择数据类型的原则: 1 业务需要 2 满足第一个条件下,需要存储空间最小的. 三.常用的选择数据类型思路:
- 在CentOS6.9 x86下编译libusb-1.0.22遇到的两个问题
OS版本:CentOS 6.9 x86,内核版本2.6.32 问题一:configure.ac:36: error: Autoconf version 2.69 or higher is requir ...
- C语言典型编程2
关于C的一些小而精的编程,适合希望提升编程能力的初学者学习:关键编程也就几句,但思维可以迁移到其他编程语言.同一问题,算法多种. //任意整数的任意次方取后3位(算数取位)#include<st ...
- docker学习-常用命令2
三.容器管理命令3.1 Docker commit 命令,从容器创建一个新的镜像.OPTIONS说明: -a :提交的镜像作者: -c :使用Dockerfile指令来创建镜像: -m :提交时的说明 ...
- Ubuntu---regex
摘要:今天我们学习正则表达式(regex),因为掌握这个是用好 grep 命令的前提条件. 1,位置相关的 patten: ^:表示锚定行首,才能匹配. $:表示锚定行尾,才能匹配. ^$:表示匹配空 ...
- 13. Roman to Integer (JAVA)
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...
- 了解计算机与操作系统发展阶段--Windows
Windows发展的30多年,其实就是整个计算机应用,从小众化向大众化消费领域,快速前行的30多年. 让我们来一起温故下Windows这么多年的发展历程,看看Windows,是如何在市场和技术这两种力 ...
- SQL Server 2000服务器安装剖析
一.情况说明 sql server 2000以前的版本,例如7.0一般不存在多个版本,只有标准版跟桌面版,用户如果不清楚该装什么版本的话,可按安装上的安装先决条件指示安装,一般在WIN2000 服务器 ...