sql 语句 字段字符串操作

substring_index() 函数 字符串截取

bash 复制代码
表达式:substring_index(column,str,count)
释义:截取字符串column,str出现从前往后数第count次,之前的所有字符
示例语句:SELECT substring_index('www.baidu.com','.',2)
结果展示: www.baidu

表达式:substring_index(column,str,-count)
释义:截取字符串column,str出现从后往前数第count次,之后的所有字符
示例语句:SELECT substring_index('www.baidu.com','.',-2)
结果展示:baidu.com

参考大神博客

replace() 字符串替换

bash 复制代码
replace(要操作的字符串,要替换操作字符串的字符,替换后的字符)
eg: 将 字符串 ,0121 中的逗号去掉
select replace(',0121',',','')
结果 : 0121

ROUND() 函数 保留多少位小数

bash 复制代码
eg 12.3456  保留两位小数
SELECT ROUND(12.3456 , 2) --12.35

参考大神博客

locate() 函数 判断某个字段属性值是否包含某个字符串

bash 复制代码
eg  判断 open_with 字段 属性值是否包含双开  >0  包含  <=0 不包含
locate('双开',open_with)

concat() 函数 字段属性值连接

bash 复制代码
eg  select concat('1','0','你是')
10你是

case when then else

bash 复制代码
CASE SCORE WHEN 'A' THEN '优' ELSE '不及格' END
CASE SCORE WHEN 'B' THEN '良' ELSE '不及格' END
CASE SCORE WHEN 'C' THEN '中' ELSE '不及格' END
bash 复制代码
(case WHEN cloth_track_type <> 3 and locate('左右拼接',work_procedure_name) > 0 then
 substring_index(replace(replace(substring_index(work_fee_rule_desc,'计价规则:',-1),',',''),' ',''),'=',-1)
       else ''
end) as pinjie_cs,

参考大神博客

相关推荐
I***t7167 小时前
一条sql 在MySQL中是如何执行的
数据库·sql·mysql
一 乐7 小时前
应急知识学习|基于springboot+vue的应急知识学习系统(源码+数据库+文档)
数据库·vue.js·spring boot
微学AI8 小时前
内网穿透的应用-突破局域网束缚,MongoDB 远程访问使用cpolar原来可以这么简单
数据库·mongodb
大锦终10 小时前
【MySQL】内置函数
数据库·mysql
猿小喵10 小时前
索引优化-MySQL性能优化
数据库·mysql·性能优化
n***F87511 小时前
修改表字段属性,SQL总结
java·数据库·sql
q***783713 小时前
mysql表添加索引
数据库·mysql
翔云12345613 小时前
MySQL 机器重启后,gtid_executed 是如何初始化的
数据库·mysql·adb
JAVA学习通14 小时前
Mysql进阶---存储过程&变量&SQL编程
数据库·mysql