SELECT s.producto,s.entrada AS entrada,r.salida AS salida,s.mes,s.anio AS anio,s.entrada-r.salida AS total
FROM (SELECT MONTH ( fecha ) AS mes,YEAR(fecha) AS anio, producto,COALESCE(SUM(cantidad),0) AS entrada FROM eProductoTerminado
WHERE ingresosalida='Ingreso' AND fecha BETWEEN '2015-01-01' AND '2017-12-31' GROUP BY producto,anio ORDER BY producto) AS s
LEFT JOIN (SELECT MONTH ( fecha ) AS mes,YEAR(fecha) AS anio,producto,COALESCE(SUM(cantidad),0) AS salida FROM eProductoTerminado
WHERE ingresosalida='Salida' AND fecha BETWEEN '2015-01-01' AND '2017-12-31' GROUP BY producto,anio ORDER BY producto) AS r ON
s.producto=r.producto AND s.mes=r.mes AND s.anio=r.anio
I have this SQL statement, the problem with this statement is that in the WHERE income = output = 'Output' in the quantity field I have a NULL value and I have another value that has value, but by grouping the value + null (eye it is not a sum, it is a GROUP BY) in the result I take it as the NULL and not as the value, I already look for how to do it but it only comes out in the case of when a SUM is done.
It's MYSQL