HAVING COUNT( n.type = 'article' ) > 3
Why this doesn't work (re: I can't find out what I'm doing wrong):
n.type = 'article'
<< this returns a BOOLEAN, which is either true/false or 1/0
- COUNT ( x ) increases the counter whenever x is NOT NULL
- both of 1/0 are not null, therefore, it counts ALL types, and is equivalent to COUNT(*)
You wanted (this answer has already been given, but repeating here)
SELECT n.uid
FROM node
WHERE n.type = 'article'
GROUP BY n.uid
HAVING COUNT( * ) > 3
In general you could also write your COUNT properly using CASE, but the WHERE filter is normally faster
SELECT n.uid
FROM node
GROUP BY n.uid
HAVING COUNT( CASE WHEN n.type = 'article' THEN 1 END ) > 3