Avatar of Tom Sage
Tom Sage
Flag for United States of America 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
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)

Open in new window

Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Tom Sage

8/22/2022 - Mon
chapmandew

select custtype, count(*) as total
from(
SELECT    CustType
FROM        Customer
ORDER BY CustType
COMPUTE COUNT(CustType)
) a
group by custtype
Tom Sage

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
ASKER CERTIFIED SOLUTION
reb73

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Tom Sage

ASKER
Hello Reb73,

Good job !   That is it exactly !

Thanks for the quick response.

Regards
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23