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
 General SQL Server Forums
 New to SQL Server Programming
 I need to use Count with distinct ?

Author  Topic 

t0ze
Starting Member

10 Posts

Posted - 2010-11-22 : 10:54:59
Hello,

Can someone help me with this one? I've this table

*TABLE 1*

Email | Action
xpto1@x.com | Delete
xpto1@x.com | Delete
xpto1@x.com | Update
xpto1@x.com | Update
xpto1@x.com | Update
xpto2@x.com | Update
xpto2@x.com | Update
xpto3@x.com | New
xpto3@x.com | New

What i need to do to get distinc e-mail's with the count of each action for example

Email | Action |Count
xpto1@x.com | Delete | 2
xpto1@x.com | Update| 3
xpto3@x.com | New | 3

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-22 : 10:57:33
select Email,Action,count(*) as [Count]
from YourTable group by Email,Action


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

t0ze
Starting Member

10 Posts

Posted - 2010-11-22 : 11:14:00
thanks a lot webfred!
^^
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-22 : 11:18:34
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -