56 lines
2.4 KiB
Markdown
56 lines
2.4 KiB
Markdown
---
|
||
title: SQL Select Distinct Statement
|
||
localeTitle: SQL选择Distinct语句
|
||
---
|
||
## SQL选择Distinct语句
|
||
|
||
### 介绍
|
||
|
||
此关键字允许我们获取列中唯一值的列表。本指南将证明这一点。
|
||
|
||
### 完整显示学生表中的数据
|
||
|
||
```sql
|
||
USE fcc_sql_guides_database;
|
||
SELECT studentID, FullName, sat_score, programOfStudy, rcd_Created, rcd_Updated FROM student;
|
||
```
|
||
|
||
```text
|
||
+-----------+------------------------+-----------+------------------+---------------------+---------------------+
|
||
| studentID | FullName | sat_score | programOfStudy | rcd_Created | rcd_Updated |
|
||
+-----------+------------------------+-----------+------------------+---------------------+---------------------+
|
||
| 1 | Monique Davis | 400 | Literature | 2017-08-16 15:34:50 | 2017-08-16 15:34:50 |
|
||
| 2 | Teri Gutierrez | 800 | Programming | 2017-08-16 15:34:50 | 2017-08-16 15:34:50 |
|
||
| 3 | Spencer Pautier | 1000 | Programming | 2017-08-16 15:34:50 | 2017-08-16 15:34:50 |
|
||
| 4 | Louis Ramsey | 1200 | Programming | 2017-08-16 15:34:50 | 2017-08-16 15:34:50 |
|
||
| 5 | Alvin Greene | 1200 | Programming | 2017-08-16 15:34:50 | 2017-08-16 15:34:50 |
|
||
| 6 | Sophie Freeman | 1200 | Programming | 2017-08-16 15:34:50 | 2017-08-16 15:34:50 |
|
||
| 7 | Edgar Frank "Ted" Codd | 2400 | Computer Science | 2017-08-16 15:35:33 | 2017-08-16 15:35:33 |
|
||
| 8 | Donald D. Chamberlin | 2400 | Computer Science | 2017-08-16 15:35:33 | 2017-08-16 15:35:33 |
|
||
| 9 | Raymond F. Boyce | 2400 | Computer Science | 2017-08-16 15:35:33 | 2017-08-16 15:35:33 |
|
||
+-----------+------------------------+-----------+------------------+---------------------+---------------------+
|
||
9 rows in set (0.00 sec)
|
||
```
|
||
|
||
### 获取学习领域列表
|
||
|
||
```sql
|
||
SELECT DISTINCT programOfStudy FROM student;
|
||
```
|
||
|
||
```text
|
||
+------------------+
|
||
| programOfStudy |
|
||
+------------------+
|
||
| Literature |
|
||
| Programming |
|
||
| Computer Science |
|
||
+------------------+
|
||
3 rows in set (0.00 sec)
|
||
```
|
||
|
||
与所有这些SQL事物一样,它们比本入门指南中的内容更多。
|
||
|
||
我希望这至少足以让你开始。
|
||
|
||
请参阅您的数据库管理员手册,并自己尝试不同的选项。 |