Skip to content
Advertisement

How to Further Group Items in a Column After Group By

I have an SQL table named “DATA” as follows:

I’m attempting to return the following 3 columns: plan, planCount, totalCostPerPlan

I’ve been working a query to return this and so far it looks like this:

It sort of works, however, I get the data only partially grouped as follows:

(The table is just an example)

How to I further group by plan? I’m trying to obtain the total value for each plan, however, they’re shown with a separate row for each mode. Please assist.

Advertisement

Answer

Hmmm . . . If you want to put factors into the sum() then the case is the argument to the sum():

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement