I have a table events that contains a type and a resourceId.
I am looking to find resources that contain all of a certain event.type
The query I have so far is:
SELECT
"resourceId",
case
WHEN array_agg(DISTINCT "type") @> '{0,1}'::INTEGER[] THEN 1
ELSE 0
END AS "containsEvents"
FROM
events
GROUP BY
"resourceId"
-- I WANT TO DO THIS vvv
-- HAVING "containsEvents" = 1
LIMIT 10;
If I'm not mistaken, MySQL allows HAVING in aliases.
Is there a way around this in Postgres?