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)
 help for count

Author  Topic 

lord_remorin
Starting Member

2 Posts

Posted - 2009-05-29 : 08:18:46
hi,

please help me, im new in using sql
i have this table

name tags
-----------
john 1st
john 1st
john 2nd
john 3rd
mark 1st
mark 2nd
mark 2nd
mark 3rd
mark 3rd
rob 1st
rob 1st
rob 3rd

and i want the result to be displayed like this

name tags count
-----------------
john 1st 2
john 2nd 1
john 3rd 1
mark 1st 1
mark 2nd 2
mark 2nd 2
rob 1st 2
rob 3rd 1

please help me build my query

thanks in advance!

LoRd

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-29 : 08:29:34
[code]
select name, tags, count = count(*)
from table
group by name, tags
[/code]


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

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-29 : 08:32:49
SELECT Name, Tags, COUNT(*) AS Count
FROM Table1
GROUP BY Name, Tags
ORDER BY Name, Tags


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-29 : 08:33:53


I was confues by the erraneous expected output...
Where is "mark 2rd" and why is "mark 2nd" twice?


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

lord_remorin
Starting Member

2 Posts

Posted - 2009-05-29 : 08:34:06
hi,
thanks a lot!
i didn't know that i could group multiple fields..
thanks again.

LoRd
Go to Top of Page
   

- Advertisement -