How to count the number of emails per domain in PostgreSQL MySQL Oracle

In this article, we will see how to count the number of emails per domain, we can use the following query in SQL Server or PostgreSQL or MySQL or Oracle or any RDBMS:

To count the number of emails per domain in PostgreSQL MySQL Oracle:

SELECT SUBSTRING( email, CHARINDEX('@', email)+1, LEN(email)-CHARINDEX('@', email) ) domain_name, COUNT(email) emails_count FROM sales.customers GROUP BY SUBSTRING( email, CHARINDEX('@', email)+1, LEN(email)-CHARINDEX('@', email) );

Output:

domain_name emails_count gmail.com 11234 ymail.com 9842 hotmail.com 2944 r2schools.com 4000 aol.com 3201

Leave a Reply

Your email address will not be published. Required fields are marked *