Tom Sage
asked on
T-SQL - How to do subtotals?
I have a table with customers and a customertype. I would like to get a subtotal of the number of customer types. Here is an example. Note that the "Total" field is not in the database.
Type Total
Good 100
Bad 25
Other 9
Thank you
Type Total
Good 100
Bad 25
Other 9
Thank you
Here is what I have done so far... IT does give a total, but not a subtotal by Type.
SELECT CustType
FROM Customer
ORDER BY CustType
COMPUTE COUNT(CustType)
ASKER
Hello,
I am getting this error:
Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'COMPUTE'.
Any ideas?
Thank you
I am getting this error:
Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'COMPUTE'.
Any ideas?
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Reb73,
Good job ! That is it exactly !
Thanks for the quick response.
Regards
Good job ! That is it exactly !
Thanks for the quick response.
Regards
from(
SELECT CustType
FROM Customer
ORDER BY CustType
COMPUTE COUNT(CustType)
) a
group by custtype