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
 count of group by

Author  Topic 

tpiazza55
Posting Yak Master

162 Posts

Posted - 2008-08-13 : 10:44:11
Is there a way when I group by a column to get the number rows that have been grouped?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-13 : 10:47:54
Yes. Use @@ROWCOUNT or put the query in a derived table and use COUNT.
We can't tell until we see your code and your objective.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-08-13 : 11:11:01
I think it's simpler if I understand the question correctly. The number of contributing rows to a GROUP BY group can be seen with "count(*)"

select <GroupByColumn(s)>, count(*) as [groupCount]
from <yourTable>
group by <column(s)>

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -