我想要另一种方法来编写以下查询
SELECT COUNT(DISTINCT col1) FROM table.
我不想使用distinct
。还有另一种方法吗?
答案 0 :(得分:2)
尝试将GROUP BY
作为子查询,并从外部查询中COUNT()
。它会达到同样的效果。
SELECT COUNT(*)
FROM
(
SELECT Col1
FROM Table
GROUP BY Col1
) tbl
答案 1 :(得分:0)
Select count(col1) from table GROUP BY col1
答案 2 :(得分:0)
试试这个
SELECT COUNT(Col1)
FROM (SELECT ROW_NUMBER() OVER (PARTITION BY Col1 ORDER BY Col1) As RNO, Col1
FROM Table_Name)
WHERE RNO = 1