我正在尝试计算不同电子邮件域的电子邮件地址数量。
name | email
---------+----------------------
Jack | jack@email.com
John | john@something.com
Mike | mike@email.com
结果应该是
domain | count
--------------+-----------------
email.com | 2
something.com | 1
答案 0 :(得分:0)
在sql server中,您可以使用:SQL HERE
select email, count(*) from (
SELECT SUBSTRING(email, CHARINDEX('@', email) + 1, 255) email from yourtable
) as T group by email
您可以在MySQL中尝试:SQL HERE
select email, count(*) from (
SELECT SUBSTRING(email, locate('@', email) + 1, 255) email from Table1
) as T group by email
答案 1 :(得分:0)
在 MySQL 中,您可以使用以下查询
SELECT SUBSTRING_INDEX(email, '@', -1) AS 'domain',
COUNT(*) AS 'count'
FROM table1
GROUP BY domain;
<强>输出强>
| domain | count |
|---------------|-------|
| email.com | 2 |
| something.com | 1 |
在此处测试此查询 MySQL Demo