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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help with group by query

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2005-02-17 : 19:19:52
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 / 2234
gmail.com / 2334
yahoo.com / 3222

Thanks 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)) domain
from userdetails
) d
group by domain
Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2005-02-17 : 19:26:44
Ehorn,

Thanks very much! worked perfectly !


mike123
Go to Top of Page

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 DomainCount
FROM @userdetails
GROUP BY SUBSTRING(emailaddress, CHARINDEX('@', emailaddress) + 1, DATALENGTH(emailaddress))
ORDER BY DomainCount DESC



Tara
Go to Top of Page

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 lol

mike123
Go to Top of Page
   

- Advertisement -