Use WHERE on result of SUM So, I have this query working great

SELECT u.username,  SUM(kort) as total
FROM user as u 
LEFT JOIN userresult as r 
on u.userID = r.userID  
WHERE r.date &gt;= '$date' 
group by u.userID
order by total DESC


But I want to remove those which the total is 0.

I tried this without any result

WHERE r.date &gt;= '$date' AND total &gt; 0


But am I not allowed to use WHERE on the result of SUM?
Just change it to INNER JOIN

SELECT u.username,SUM(kort) as total
FROM user as u 
INNER JOIN userresult as r 
on u.userID = r.userID  
WHERE r.date &gt;= '$date' 
group by u.userID
order by total DESC;


or put the WHERE clause in the HAVING aggregation

SELECT u.username,SUM(kort) as total
FROM user as u 
LEFT JOIN userresult as r 
on u.userID = r.userID  
WHERE r.date &gt;= '$date' 
group by u.userID
HAVING SUM(kort) &gt; 0;


or put the whole thing in a subquery and test the total outside the subquery

SELECT * FROM
(
    SELECT u.username,SUM(kort) as total
    FROM user as u 
    LEFT JOIN userresult as r 
    on u.userID = r.userID  
    WHERE r.date &gt;= '$date' 
    group by u.userID
    order by total DESC
) A WHERE total &gt; 0;


The simplest and most sensible is the INNER JOIN