数据库表列中数据如何返回唯一值

来源:网络时间:2017-02-21 15:03:55

word-wrap: break-word; white-space: normal; font-size: 13px;">在表中,一个列可能会包含多个重复值,有时您也许希望仅仅列出不同(distinct)的值。

DISTINCT 关键词便可以用来解决这个问题。

我们将使用众所周知的 Northwind 样本数据库。下面是选自 "Customers" 表的数据:



CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1

Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4

Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

下面的 SQL 语句仅从 "Customers" 表的 "City" 列中选取唯一不同的值。从 Company" 列中仅选取唯一不同的值:

SELECT DISTINCT City FROM Customers

文章内容来源于网络,不代表本站立场,若侵犯到您的权益,可联系我们删除。(本站为非盈利性质网站) 联系邮箱:rjfawu@163.com