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 2005 Forums
 Transact-SQL (2005)
 summing tables

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2009-05-26 : 02:46:36
i have a table like this:
user,target,uniqueid,datetime,phone
the data look like this :
a,x1,w3e23e,20090501125124,4521424
a,x1,w3e23e,20090501125124,4521424
a,x2,w3ezzz,20090501125124,4521424
a,x2,w3ezzz,20090501125124,4521424
a,x2,w3ezzz,20090501125124,4521424

and i want to count
for each "user+target",how many times rows return on themself one time,two times or three times.
for exampme :
user a with target x1 appears twice
user a with target x2 appears three times.

Thnaks in advace
peleg




Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-26 : 02:48:33
[code]
select user, target, count(*)
from tablea
group by user, target
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-05-26 : 02:49:28
select distinct user,target, count(*) from tablename
group by user,target
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-26 : 02:57:31
quote:
Originally posted by bklr

select distinct user,target, count(*) from tablename
group by user,target


Why distinct there ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -