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,

参考大神博客

相关推荐
垂金烟柳2 分钟前
CentOS 7上配置SQL Server链接其他SQL Server服务器
服务器·数据库·sqlserver
一期一祈^1 小时前
使用MySQL时出现 Ignoring query to other database 错误
数据库·mysql
Mr.wangh1 小时前
Spring Boot 打印日志
java·数据库·spring boot
BenBen尔2 小时前
innodb如何实现mvcc的
数据库
孪生质数-2 小时前
2-Visual Studio 2022 NET开发Windows桌面软件并连接SQL Server数据库
数据库·windows·sqlserver·visual studio
T0uken3 小时前
【LLM】MCP(Python):实现 SSE 通信的 Server 和 Client
数据库·python·microsoft
死磕java的孤行者4 小时前
Redis 分布式锁
数据库·redis·分布式
越甲八千4 小时前
pyqt SQL Server 数据库查询-优化2
数据库·windows·pyqt
敢敢のwings5 小时前
C++信号与槽机制自实现
开发语言·数据库·c++
杭州杭州杭州6 小时前
MySQL超全笔记
数据库·笔记·mysql