表A:

表B:

select distinct name from A
執行后結果如下:

select distinct name, id from A
執行后結果如下:

實(shí)際上是根據name和id兩個(gè)字段來(lái)去重的,這種方式Access和SQL Server同時(shí)支持。
select distinct xing, ming from B
返回如下結果:

select count(distinct name) from A; --表中name去重后的數目, SQL Server支持,而Access不支持
count是不能統計多個(gè)字段的,下面的SQL在SQL Server和Access中都無(wú)法運行。
select count(distinct name, id) from A;
若想使用,請使用嵌套查詢(xún),如下:
select count(*) from (select distinct xing, name from B) AS M;
select id, distinct name from A; --會(huì )提示錯誤,因為distinct必須放在開(kāi)頭
聯(lián)系客服