Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 不同值的count()_Sql_Count_Group By_Duplicates - Fatal编程技术网

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