Substring_index function of MySQL

Source: Internet
Author: User

The substring_index function of MySQL assumes that there is a table in which a field is saved by email. Then, I want to count the proportion of each mailbox. We know that the email address format is account @ domain. To achieve the above statistics, you must obtain an email
The domain name following @ in the string. MySQL provides a function named substring_index to meet our needs: MySQL 5.5 Reference 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. mysql> 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. the query statement for www.2cto.com 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; Author: codingstandards

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.