Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a table with all my users named "userdetails"I have a column named "emailaddress" that stores the users email address.I want to find out the most popular email service providers, for example - hotmail, gmail, yahoo etc...How can I write a query that will do this ? My desired results would look something like this ..hotmail.com / 2234gmail.com / 2334yahoo.com / 3222Thanks alot for any help!mike123
ehorn
Master Smack Fu Yak Hacker
1632 Posts
Posted - 2005-02-17 : 19:24:02
Maybe something like:
select domain, count(domain)from(select substring(emailaddress, charindex('@',emailaddress,1)+1,len(emailaddress)) domainfrom userdetails) dgroup by domain
mike123
Master Smack Fu Yak Hacker
1462 Posts
Posted - 2005-02-17 : 19:26:44
Ehorn,Thanks very much! worked perfectly ! mike123
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2005-02-17 : 19:27:58
Here's what I came up with:
SELECT SUBSTRING(emailaddress, CHARINDEX('@', emailaddress) + 1, DATALENGTH(emailaddress)) AS Domain, COUNT(emailaddress) AS DomainCountFROM @userdetailsGROUP BY SUBSTRING(emailaddress, CHARINDEX('@', emailaddress) + 1, DATALENGTH(emailaddress))ORDER BY DomainCount DESC
Tara
mike123
Master Smack Fu Yak Hacker
1462 Posts
Posted - 2005-02-17 : 19:35:45
thanks tara, that worked great too! .. you guys are way too quick today lolmike123