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 2008 Forums
 Transact-SQL (2008)
 count rows

Author  Topic 

Exir
Posting Yak Master

151 Posts

Posted - 2009-12-29 : 03:13:18
Hi
I have a table like this:
code - color - weight
100 - red - 50
100 - blue - 54
100 - pink - 70
200 - red -120
200 - yellow - 150
200 - brown - 130
200 - blue -120
300 - red - 34

i want to write a command to show how many goals there are in the table. each code is belong to one goal and for this example it should return three
I thought it should be something like this:
select count(select count(*) from table group by code)
but it doesnt work and the outer select can not count the rows of inner select
please give me some guidance

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-29 : 03:26:08
select count(counting) from
(
select count(*) as counting from table group by code
) as t

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2009-12-29 : 03:38:25
Thanks alot
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-29 : 04:44:28
Try this too


select top 1 count(*) from table group by code
WITH Rollup order by code

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-29 : 06:06:45
quote:
Originally posted by senthil_nagore

Try this too


select top 1 count(*) from table group by code
WITH Rollup order by code

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/



This is incorrect and also most ineffecient

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -