First off, I'm not an expert with MySQL queries, and I can't seem to find a solution to my problem.
Example:
SELECT SUM(IF(table1.col1<4,1,0)) AS score WHERE score>0 GROUP BY table1.col2
The above would give an error as the column score does not exist in table1.
This is my workaround:
SELECT SUM(IF(table1.col1<4,1,0)) AS score GROUP BY table1.col2
Then checking each row in PHP
if($row['score']>0){...
There is a performance issue as I'm looping through rows that I know I will not need, ideally I need to ignore those rows within the query.
My understanding is that the WHERE clause is triggered for each row of the table, not the grouped row.
Is there a way to do this?