当前位置:网站首页>SQL substring_index() usage - MySQL string interception
SQL substring_index() usage - MySQL string interception
2022-07-30 08:39:00 【embelfe_segge】
Table of Contents
1. The syntax of the substring_index function and its usage
(1) Syntax: substring_index(string,sep,num)
(2) is used to intercept the target string.
(1) From aField intercepts the target string.
1.The syntax of the substring_index function and its usage
(1) Syntax: substring_index(string,sep,num)
That is, substring_index (string, separator, serial number)
Parameter description
string: The string used to intercept the target string.Can be fields, expressions, etc.
sep: Separator, a character that exists and is used to separate strings, such as ",", ".", etc.
num: serial number, which is a non-zero integer.If it is an integer, it counts from left to right, and if it is a negative number, it counts from right to left.For example, "www.mysql.com" intercepts the character 'www', the separator is ".", and the sequence number from left to right is 1, that is, substring_index("www.mysql.com",'.',1);To start getting "com", the serial number is -1, that is, substring_index("www.mysql.com",'.',-1)
(2) is used to intercept the target string.
2.Instance
(1) Intercept the target string from a field.
Example: There is a student information table student, and the detailed address address stores the address information separated by commas such as province, city, county, such as "XX province, XX city, XX district, ..., XXX number".For some reason, there is no information about the province where the student is located. At the same time, the student's name, gender, and age are obtained.
select name,sex,age,substring_index(address,',',1) as provincefrom student(2) Combine with the cast function to intercept a string and convert it to the target format.
Example: There is an existing order information data. Since the format of the date information stored after the date of 2022-03-04 is wrong, some prefixes are added before the date and separated by spaces, such as "13d 2022-02-01".Obtain the specific date information after 2022-03-04 in the table, and obtain the list offer_id and product name at the same time.
select cast(substring_index(ctime,' ',1) as date) as dt,offer_id,nameFROM dataWHERE substring_index(ctime,' ',1)>= '2022-03-04'For the usage of cast function in SQL, please refer toSQL's CAST() - Converting Data Types_'s Blog-CSDN Blog
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
猜你喜欢

SwiftUI SQLite 教程之 构建App本地数据库实现创建、读取、更新和删除(教程含完成项目源码)

实现定时器

IDEA 中CheckStyle安装及使用

typescript3-ts对比js的差别

Map file analysis in Keil software

Selected as one of the "Top Ten Hard Core Technologies", explaining the technical points of Trusted Confidential Computing (TECC) in detail

selenium模块

Mybitatis related configuration files

DP5340国产替代CM5340立体声音频A/D转换器芯片

RFID固定资产盘点系统给企业带来哪些便利?
随机推荐
SQL的substring_index()用法——MySQL字符串截取
风险登记册
Hex conversion...
redis伪集群搭建
MySQL off-topic [ORM thought analysis]
风靡全球25年的重磅IP,新作沦为脚本乐园
如何实时计算日累计逐单资金流
潜心打磨,主动求变——这群技术排头兵,如何做好底层开发这件事?
SE11 创建搜索帮助
SOFA Weekly|Meetup 广州站、本周 QA、本周 Contributor
A magical no main method of code
C13—使用innosetup工具制作软件安装向导2022-07-23
【BERT-多标签文本分类实战】之二——BERT的地位与名词术语解释
go : go-redis list operation
C语言力扣第46题之全排列。回溯法
sizeof
SwiftUI SQLite 教程之 构建App本地数据库实现创建、读取、更新和删除(教程含完成项目源码)
linux安装mysql8参考指引
Leetcode 2.两数相加 两个非空的链表,表示两个非负的整数。它们每位数字都是按照逆序的方式存储的。
2022年施工企业数字化转型思考,施工企业数字化转型之路