SQL: Count of email domain names

The script below, returns the number of records grouped by the domain name of each email address (i.e. to the right of the @ sign).

 
SELECT
  RIGHT(Email, LEN(EMAIL) - CHARINDEX('@', EMAIL)) AS EmailDomain, 
  COUNT(*) EmailCount
FROM
  Users S
GROUP BY 
  RIGHT(EMAIL, LEN(EMAIL) - CHARINDEX('@', EMAIL))
ORDER BY
  EmailCount DESC

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.