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