采取以下示例
CREATE TABLE #repeated ( iValue int NOT NULL)
INSERT INTO #repeated
VALUES(1),(1),(2),(3),(4),(5),(5),(5),(6),(7)
SELECT * FROM #repeated
SELECT
count(*) as countAsterisco
,count(iValue) as countValue
FROM #repeated
countAsterisco和countValue都会产生10,因为两个计数都考虑重复值。我只需计算不同的值,因此结果必须为7。
有功能吗?我以为count(iValue)
会这样做。
答案 0 :(得分:4)
select count(distinct iValue) from #repeated