SQL SUM来自内部查询的COUNT

时间:2012-11-27 16:10:17

标签: sql-server

如何从这样的内部查询中总结一列?显然这不起作用,但它本质上是我想要做的。这里有很多类似的帖子,但这是独一无二的,因为我的帖子有HAVING

SELECT SUM(cnt)
FROM
    (
        SELECT COUNT(*) as cnt
        FROM users
        GROUP BY email
        HAVING COUNT(*)>1
    )

1 个答案:

答案 0 :(得分:1)

如果你有查询的别名,你写的内容应该有用

SELECT SUM(cnt)
FROM
    (
        SELECT COUNT(*) as cnt
        FROM users
        GROUP BY email
        HAVING COUNT(*)>1
    ) as t

SQL Fiddle