20 ) as x"> 20 ) as x"> 20 ) as x">
SELECT SUM(cnt) FROM (
SELECT COUNT(*) as cnt FROM "_messageToInstance"
JOIN messages
ON messages.id = "_messageToInstance"."messageId"
JOIN "instances"
ON instances.id = "_messageToInstance"."instanceId"
WHERE messages.type = 'email'
GROUP BY "instanceId"
HAVING COUNT(*) > 20
) as x