Krapulator
asked on
DISTINCT Query with totals
I have a table with a "Cat" field and a "SubCat" field.
I need a SQL query which returns the distinct SubCats for a given Cat and the total number of SubCats found for each distinct SubCats
My Table:
Cat Subcat
-------- ----------
1 1
1 2
1 3
1 3
I want the query to return the distinct Subcats with totals for the given cat. Thus if my Cat was 1 as in the above example, I want the query to return:
Subcat Total
-------- ---------
1 1
2 1
3 2
I need a SQL query which returns the distinct SubCats for a given Cat and the total number of SubCats found for each distinct SubCats
My Table:
Cat Subcat
-------- ----------
1 1
1 2
1 3
1 3
I want the query to return the distinct Subcats with totals for the given cat. Thus if my Cat was 1 as in the above example, I want the query to return:
Subcat Total
-------- ---------
1 1
2 1
3 2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect. Thanks!
SELECT COUNT(*) As Total, SubCat
FROM Table
GROUP BY SubCat