I have this query
SELECT
`presupuesto_annio_real`.`categoria`,
IF(`clase_canal`.`canal` = 'constructor',sum(`presupuesto_annio_real`.`cantidad`),0) as constructorCantidad,
IF(`clase_canal`.`canal` = 'distribuidor',sum(`presupuesto_annio_real`.`cantidad`),0) as distribuidorCantidad,
IF(`clase_canal`.`canal` = 'salas',sum(`presupuesto_annio_real`.`cantidad`),0) as salasCantidad
FROM
`presupuesto_annio_real`
INNER JOIN `clase_canal` ON (`presupuesto_annio_real`.`clase` = `clase_canal`.`clase`)
where `presupuesto_annio_real`.`referencia` = '200142'
GROUP BY
`presupuesto_annio_real`.`categoria`,
`clase_canal`.`canal`
and it gives me the following result
----------------------------------------------------------------
categoria|contructorCantidad|distribuidorCantidad|SalasCantidad|
---------------------------------------------------------------
di |200 | 0 | 0
---------------------------------------------------------------
di | 0 | 32 | 0
---------------------------------------------------------------
di | 0 | 0 | 9
---------------------------------------------------------------
and I need the result to be the following
----------------------------------------------------------------
categoria|contructorCantidad|distribuidorCantidad|SalasCantidad|
---------------------------------------------------------------
di |200 | 32 | 9 |
---------------------------------------------------------------
You can reverse the condition and only group by category, like so:
This should give you the expected result.
In your WHERE try adding that they are different from 0 so you will get the result you want without the zero like the following example:
I hope I can help you