I have this query below where I get the sum of the insurance type. How can I get the sum of Basic, Option 1, and Voluntary 2 and name it with Short-Term? Thanks for all the help.

I have this query below where I get the sum of the insurance type. How can I get the sum of Basic, Option 1, and Voluntary 2 and name it with Short-Term? Thanks for all the help.

Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Aug 31, 2023, 5:35 AM EDT
To get the sum of the insurance types "Basic," "Option 1," and "Voluntary 2" and name it as "Short-Term," you can use a CASE statement to categorize the different insurance types and then group by the new category.
SELECT COUNT(MotorCINo) AS PolicyCount, SUM(a.TotalPremium) AS TotalPremium, CASE WHEN a.InsuranceType IN ('Basic', 'Option 1', 'Voluntary 2') THEN 'Short-Term' ELSE a.InsuranceType END AS InsuranceCategory FROM tblMotorInsurance_eCI a GROUP BY InsuranceCategory;