freeCodeCamp/guide/chinese/sql/sql-where-clause/index.md

68 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: SQL Where Clause
localeTitle: SQL Where子句
---
## SQL Where子句
### `WHERE`子句(和/或, `IN` `BETWEEN`和`LIKE`
`WHERE`子句用于限制返回的行数。
在这种情况下,所有这五个将被使用的是一些荒谬的`WHERE`子句。
以下是与`WHERE`子句结果集进行比较的当前完整学生列表:
```sql
select studentID, FullName, sat_score, rcd_updated from student;
```
```text
+-----------+------------------------+-----------+---------------------+
| studentID | FullName | sat_score | rcd_updated |
+-----------+------------------------+-----------+---------------------+
| 1 | Monique Davis | 400 | 2017-08-16 15:34:50 |
| 2 | Teri Gutierrez | 800 | 2017-08-16 15:34:50 |
| 3 | Spencer Pautier | 1000 | 2017-08-16 15:34:50 |
| 4 | Louis Ramsey | 1200 | 2017-08-16 15:34:50 |
| 5 | Alvin Greene | 1200 | 2017-08-16 15:34:50 |
| 6 | Sophie Freeman | 1200 | 2017-08-16 15:34:50 |
| 7 | Edgar Frank "Ted" Codd | 2400 | 2017-08-16 15:35:33 |
| 8 | Donald D. Chamberlin | 2400 | 2017-08-16 15:35:33 |
| 9 | Raymond F. Boyce | 2400 | 2017-08-16 15:35:33 |
+-----------+------------------------+-----------+---------------------+
9 rows in set (0.00 sec)
```
行将呈现......
* `WHERE`学生ID是1和5之间
* `OR` studentID = 8
这是一个更新的查询其中将不会显示具有此列表1000,1400中的SAT分数的任何记录
```sql
select studentID, FullName, sat_score, recordUpdated
from student
where (studentID between 1 and 5 or studentID = 8)
and
sat_score NOT in (1000, 1400);
```
```text
+-----------+----------------------+-----------+---------------------+
| studentID | FullName | sat_score | rcd_updated |
+-----------+----------------------+-----------+---------------------+
| 1 | Monique Davis | 400 | 2017-08-16 15:34:50 |
| 2 | Teri Gutierrez | 800 | 2017-08-16 15:34:50 |
| 4 | Louis Ramsey | 1200 | 2017-08-16 15:34:50 |
| 5 | Alvin Greene | 1200 | 2017-08-16 15:34:50 |
| 8 | Donald D. Chamberlin | 2400 | 2017-08-16 15:35:33 |
+-----------+----------------------+-----------+---------------------+
5 rows in set (0.00 sec)
```
\*与所有这些SQL事物一样它们比本入门指南中的内容更多。
我希望这至少足以让你开始。
请参阅您的数据库管理员手册,并自己尝试不同的选项。