Sql 不同值的count()
以下面的例子为例Sql 不同值的count(),sql,count,group-by,duplicates,Sql,Count,Group By,Duplicates,以下面的例子为例 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 两个计数均考虑重复值,结果
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
两个计数均考虑重复值,结果为10。我只需要计算不同的值,所以结果必须是7
有这样的功能吗?我想,count(iValue)
就可以了
select count(distinct iValue) from #repeated