欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SQL select distinct的使用方法

 更新時間:2015年11月03日 23:30:52   投稿:mdxy-dxy  
這篇文章主要介紹了SQL中distinct的用法 ,需要的朋友可以參考下

在表中,可能會包含重復值。這并不成問題,不過,有時您也許希望僅僅列出不同(distinct)的值。關鍵詞 distinct用于返回唯一不同的值。

表A:

示例1

復制代碼 代碼如下:

select distinct name from A

執(zhí)行后結果如下:

示例2
select distinct name, id from A

執(zhí)行后結果如下:

實際上是根據(jù)“name+id”來去重,distinct同時作用在了name和id上,這種方式Access和SQL Server同時支持。

示例3:統(tǒng)計

select count(distinct name) from A; --表中name去重后的數(shù)目, SQL Server支持,而Access不支持
select count(distinct name, id) from A; --SQL Server和Access都不支持

示例4

select id, distinct name from A; --會提示錯誤,因為distinct必須放在開頭

其他

distinct語句中select顯示的字段只能是distinct指定的字段,其他字段是不可能出現(xiàn)的。例如,假如表A有“備注”列,如果想獲取distinc name,以及對應的“備注”字段,想直接通過distinct是不可能實現(xiàn)的。
但可以通過其他方法實現(xiàn)關于SQL Server將一列的多行內容拼接成一行的問題討論

相關文章

最新評論