MySQL – sum column value(s) based on row from the same table
I think you’re making this a bit more complicated than it needs to be. SELECT ProductID, SUM(IF(PaymentMethod = ‘Cash’, Amount, 0)) AS ‘Cash’, — snip SUM(Amount) AS Total FROM Payments WHERE SaleDate=”2012-02-10″ GROUP BY ProductID