Reputation: 14279
How do I sum up a column from an inner query like this? Obviously this doesnt work but it is essentially what I am trying to do. There are a lot of similar posts to this but this is unique in that mine has a HAVING
clause.
SELECT SUM(cnt)
FROM
(
SELECT COUNT(*) as cnt
FROM users
GROUP BY email
HAVING COUNT(*)>1
)
Upvotes: 0
Views: 107
Reputation: 52645
What you wrote should work provided you have an alias for your query
SELECT SUM(cnt)
FROM
(
SELECT COUNT(*) as cnt
FROM users
GROUP BY email
HAVING COUNT(*)>1
) as t
Upvotes: 1