Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of substring_index function in MySQL

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you what the function of substring_index in MySQL is. The content is concise and easy to understand. It can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

A brief Analysis of substring_index function of MySQL

Suppose there is a table with a field in which email holds the e-mail address, and then I want to count the proportion of each mailbox.

We know that the format of the e-mail box is: account@domain. To achieve the above statistics, we must get email.

The part of the domain name after @ in the string.

MySQL provides a function called substring_index that meets our needs:

MySQL 5.5Reference Manual wrote www.2cto.com

SUBSTRING_INDEX (str,delim,count)

Returns the substring from string str before count occurrences of the delimiter delim.

If count is positive, everything to the left of the final delimiter (counting from the left)

Is returned. If count is negative, everything to the right of the final delimiter (counting

From the right) is returned. SUBSTRING_INDEX () performs a case-sensitive match when

Searching for delim.

> SELECT SUBSTRING_INDEX ('www.mysql.com','. 2)

-> 'www.mysql'

Mysql > SELECT SUBSTRING_INDEX ('www.mysql.com','.'- 2)

-> 'mysql.com'

This function is multi-byte safe.

Www.2cto.com

The query statement is as follows:

Sql code

Select

Substring_index (email,'@',-1) as domain

Count (distinct email) as count

Count (distinct email)

/ (select count (distinct email) from qzt_resume_basic where email like'% @%')

* 100 as percent

From qzt_resume_basic

Where email like'% @%'

Group by 1

Order by 2 desc

Limit 10

The above is what is the function of substring_index function in MySQL. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report