MySQL SUM IF field b = field a

mysql

Solution

If I'm reading that right, you'd need to use a group-by or at least a where clause to restrict things to just the time range you're wanting:

SELECT incMonth AS Month, SUM(IF(item_type IN('typ1', 'typ2'), 1, 0)) AS 'Total Sales'
FROM tester
GROUP BY incMonth

Problem

``` SELECT incMonth as Month, SUM( IF(item_type IN('typ1', 'typ2') AND incMonth = Month, 1, 0 ) )AS 'Total Sales' FROM tester ``` I just need the sum for the current month its looping through.

Original source