WHERE
子句(和/或, IN
, BETWEEN
和LIKE
)
WHERE
子句用于限制返回的行数。
在这种情况下,所有这五个将被使用的是一些荒谬的WHERE
子句。
以下是与WHERE
子句结果集进行比较的当前完整学生列表:
select studentID, FullName, sat_score, rcd_updated from student;
+-----------+------------------------+-----------+---------------------+
| 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分数的任何记录:
select studentID, FullName, sat_score, recordUpdated
from student
where (studentID between 1 and 5 or studentID = 8)
and
sat_score NOT in (1000, 1400);
+-----------+----------------------+-----------+---------------------+
| 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事物一样,它们比本入门指南中的内容更多。
我希望这至少足以让你开始。
请参阅您的数据库管理员手册,并自己尝试不同的选项。
更多SQL教程
学习更多SQL教程