在表中,可能会包含重复值。关键词 distinct用于返回唯一不同的值。
1. 数据表准备
| Customer_N | Produce_N | Key |
|---|---|---|
| 张三 | HUAWEI | 1 |
| 李四 | HUAWEI | 1 |
| 王五 | IPHONE | 1 |
| TOM | XIAOMI | 1 |
| 张三 | IPHONE | 2 |
| MORRI | XIAOMI | 1 |
| MORRI | HUAWEI | 2 |
1.1 作用于单列(去重Customer_N的数据)
select distinct Customer_N from [Test].[dbo].[distinct]
查询结果
1.2 作用于多列(去重Customer_N,Produce_N的数据)
select distinct Customer_N,Produce_N from [Test].[dbo].[distinct]