Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying the count

Status
Not open for further replies.

SuperTime

Programmer
Dec 21, 2004
183
US
My database has say abt 8 Categoreies and each category has one or more sub categories.
Eg:
Categorey Count(Sub-Category)
1 2
2 1
3 2
4 3
5 3
6 2
7 5
8 4

So from above we see that category number 4 has 3 subcategories.

I wrote the following query to get the above output:

select count(sub-categorey) from table_name where Group By Category

But now I want to select a count of the Categories with more than 3 sub categories.

So I want the following output
Count(category)
2

Because there are two categories that have more than 3 sub-categories i.e. categorey number 7 and 8.


Please tell me what will be the query for that.
 
SELECT Count(*) AS [Count(category)] FROM (
SELECT Count([Sub-Category]) FROM table_name GROUP BY Category HAVING Count(*)>3
) A;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top