bitsCN.com
MySQL的substring_index函数简析 假定有一张表,其中有个字段是 email 保存了电子邮箱,然后,我想统计每种邮箱的占比情况。我们知道电子信箱的格式是: account@domain ,要实现上面的统计,必须取得 email
字符串中 @ 后面的域名部分。MySQL提供了一个名为 substring_index 的函数,能够满足我们的需求:MySQL 5.5 Reference Manual 写道 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. 查询语句如下:Sql代码 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; 作者 codingstandards bitsCN.com
0
0
相关文章
mysql中的权限错误与权限表修复方法
什么是联合索引_mysql复合索引原理
mysql如何实现基础缓存表_mysql项目性能优化
mysql中GROUP BY与聚合函数的执行过程
mysql安装后如何设置字符集和排序规则_mysql编码环境设置
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
2026赚钱平台入口大全
2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。
268
2026.01.31
无需付费的漫画app大全
想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。
170
2026.01.31
漫画免费在线观看地址大全
想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。
85
2026.01.31
热门下载
精品课程
相关推荐
/
热门推荐
/
最新课程






