Skip to content
Advertisement

Pivot Queries – trouble with SUM()

I have the following query:

Right now I am able to get the table to populate but it does not sort by the payment_type. For instance it will sum all of the payments in MedPay or Liability but won’t split them as a pivot table would. What would be the best way to do this? Here is the table structure:

I want the output to look like

Advertisement

Answer

–>

Or you could change 0 to NULL. I think this would end up with a blank for the value instead of 0 (when no entries in the table have type_id=1).

Or, to get “none” displayed:

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