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,

参考大神博客

相关推荐
christine-rr8 分钟前
数据库基础概念体系梳理
数据库·oracle
SirLancelot125 分钟前
StarRocks-基本介绍(一)基本概念、特点、适用场景
大数据·数据库·数据仓库·sql·数据分析·database·数据库架构
Boop_wu1 小时前
[MySQL] 基础操作
数据库·mysql
6极地诈唬1 小时前
【sqlite】xxx.db-journal是什么?
数据库·sqlite
小糖学代码2 小时前
MySQL:14.mysql connect
android·数据库·mysql·adb
wudl55663 小时前
Flink SQL 窗口函数详细
sql·flink·linq
爬山算法3 小时前
Redis(69)Redis分布式锁的优点和缺点是什么?
数据库·redis·分布式
RestCloud3 小时前
从数据库到价值:ETL 工具如何打通南大通用数据库与企业应用
数据库
惜月_treasure4 小时前
Text2SQL与工作流实现:让数据库查询变得轻松又高效
数据库·人工智能·python
-睡到自然醒~4 小时前
[go 面试] 并发与数据一致性:事务的保障
数据库·面试·golang