I’ve got the following SQL, but I only want to return rows where ‘hits’ are greater than 10.
SELECT clicks.affiliate, COUNT(*) AS hits, affiliates.title, affiliates.url
FROM clicks
INNER JOIN affiliates ON affiliates.id = clicks.affiliate
GROUP BY clicks.affiliate
Thanks.
To filter by an aggregate you need to use the
havingclause. Unlike many RDBMSs MySQL does allow you to use the column alias in this context (Most other RDBMSs would also insist onaffiliates.title, affiliates.urlbeing added to thegroup byclause as well)