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
 How to get number of group?

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2011-12-07 : 13:50:42
Hi there,

If I run

select count(Country) from table
group by Country


then I get sum of each country, like this

3 (for America)
4 (for UK)
5 (for Japan)

but how can I know how many groups of countries in there (here there are three)?

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-12-07 : 14:00:08
Are you looking for @@ROWCOUNT?
Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 2011-12-07 : 23:06:42
well, @@ROWCOUNT is a way, anything else? Thanks.
Go to Top of Page

raguyazhin
Posting Yak Master

105 Posts

Posted - 2011-12-07 : 23:37:07
Select Count(*) From (
select Count(Country) As CCount from
(Select 'America' As Country
Union All
Select 'America'
Union All
Select 'America'
Union All
Select 'UK'
Union All
Select 'UK'
Union All
Select 'Japan'
Union All
Select 'Japan'
Union All
Select 'Japan'
Union All
Select 'India')V
group by Country
)VV
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-08 : 01:34:09
[code]
select count(distinct Country) from table
[/code]



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 2011-12-08 : 11:56:53
quote:
Originally posted by visakh16


select count(distinct Country) from table




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





That's what I am looking for!!! Thank you visakh16!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-08 : 12:26:54
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -