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,

参考大神博客

相关推荐
zjttsh12 分钟前
MySQL 数据库基础
数据库·mysql·oracle
万邦科技Lafite1 小时前
淘宝店铺所有商品API接口实战指南
java·数据库·mysql
mqffc2 小时前
Mysql 驱动程序
数据库·mysql
wl85112 小时前
SAP-CPI-SF问题收集009 user id is either invalid or purged
数据库
摩拜芯城IC2 小时前
RS -485/RS -422 全双工收发器 ISO3086TDW芯片参数资料 驱动集成 IC
数据库
e***13623 小时前
MySQL 常用 SQL 语句大全
数据库·sql·mysql
yueyin1234563 小时前
MySQL 批量插入详解:快速提升大数据导入效率的实战方法
大数据·数据库·mysql
kiss strong3 小时前
同一无线网下两台笔记本,一台访问另一台虚拟机中服务(redis为例)
数据库·redis·缓存
星火开发设计3 小时前
模板参数:类型参数与非类型参数的区别
java·开发语言·前端·数据库·c++·算法
山岚的运维笔记4 小时前
SQL Server笔记 -- 第53章:INSERT 第54章:主键
数据库·笔记·sql·microsoft·sqlserver