请在SQL帮助上进行数据完整性检查

时间:2014-12-01 14:50:20

标签: sql count distinct

我有一个问题:

Select distinct yearend, customerid from table1

返回行数为3(SSMS右下角):

Yearend      CustomerID
2011-03-31   3
2013-10-31   5
2013-12-31   6

我需要做的是得到上面的计数,只返回3的值。

我已尝试过多种变体,但不能只返回' 3'作为计算总数。

4 个答案:

答案 0 :(得分:1)

您只需COUNT查询结果:

SELECT COUNT(*)
FROM (
    SELECT DISTINCT yearend, customerid
    FROM table1
)

答案 1 :(得分:0)

SELECT count(DISTINCT CustomerID)
FROM table1
GROUP BY CustomerID

答案 2 :(得分:0)

你需要特别统计吗?

SELECT COUNT(*)
FROM (
SELECT DISTINCT yearend, customerid
FROM table1
)

答案 3 :(得分:0)

select count(*) from
(select distinct yearend, customerid from table1);