count duplicates and return
-
2012年7月4日 9:26
Hi!
I have a table of emails addresses
like this:
alex@hotmail.co.uk
allen@hotmail.co.uk
kens@aol.com
clifty@aol.com
clifty@aol.com
clifty@aol.com
esta@virgin.net
james@btinternet.com
james@btinternet.com
winnie@btinternet.com
pu@talktalk.net
trustl@aol.com
trustl@aol.com
james@btinternet.comAnd I need to write some sql to count the occurances of each - so the output would look something like:
alex@hotmail.co.uk 1
allen@hotmail.co.uk 1
kens@aol.com 1
clifty@aol.com 3
esta@virgin.net 1
james@btinternet.com 3
winnie@btinternet.com 1
pu@talktalk.net 1
trustl@aol.com 2
trustl@aol.com 1
any idea how to do this?
Cheers
Zoe
全部回复
-
2012年7月4日 9:27答复者
select count(*), emails from tbl
group by emails
Best Regards,Uri Dimant SQL Server MVP,http://sqlblog.com/blogs/uri_dimant/
- 已建议为答案 Steven Wang - Shangzhou 2012年7月4日 9:29
- 已标记为答案 Zoe.Ohara 2012年7月4日 9:39
-
2012年7月4日 9:31
Select EMAILID, COUNT(*) from <tablename> group by EMAILID
Please click the Mark as Answer or Vote As Helpful if a post solves your problem or is helpful!
-
2012年7月4日 9:37
Select email_addr,count(*)
from tab1
group by email_addr
order by 1;
Many Thanks & Best Regards, Hua Min
- 已编辑 HuaMin ChenMicrosoft Community Contributor 2012年7月4日 9:37
- 已建议为答案 HuaMin ChenMicrosoft Community Contributor 2012年7月4日 9:46
-
2012年7月4日 9:38
Do the group by on emails to get the number of occurance for emails with count(*).
see below query :
SELECT count(*), emails FROM Yourtable GROUP BY emails
Please vote if you find this posting was helpful or Mark it as answered.
-
2012年7月4日 9:39
Thank you!
I feel stupid it was that easy!
-
2012年7月6日 5:40use distinct count

