SQL AND & OR 运算符

SQL 教程 · 2019-03-03 15:43:51

AND & OR 运算符用于基于一个以上的条件对记录进行过滤。

SQL AND & OR 运算符

如果第一个条件和第二个条件都成立,则 AND 运算符显示一条记录。

如果第一个条件和第二个条件中只要有一个成立,则 OR 运算符显示一条记录。

演示数据库

在本教程中,我们将使用 CODERCTO 样本数据库。

下面是选自 "Websites" 表的数据:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/    | 1     | USA     |
| 2  | 淘宝          | https://www.taobao.com/   | 13    | CN      |
| 3  | 码农教程      | http://www.codercto.com/    | 4689  | CN      |
| 4  | 微博          | http://weibo.com/         | 20    | CN      |
| 5  | Facebook     | https://www.facebook.com/ | 3     | USA     |
+----+--------------+---------------------------+-------+---------+

AND 运算符实例

下面的 SQL 语句从 "Websites" 表中选取国家为 "CN" 且alexa排名大于 "50" 的所有网站:

实例

SELECT * FROM Websites WHERE country='CN' AND alexa > 50;

OR 运算符实例

下面的 SQL 语句从 "Websites" 表中选取国家为 "USA" 或者 "CN" 的所有客户:

实例

SELECT * FROM Websites WHERE country='USA' OR country='CN';

结合 AND & OR

您也可以把 AND 和 OR 结合起来(使用圆括号来组成复杂的表达式)。

下面的 SQL 语句从 "Websites" 表中选取 alexa 排名大于 "15" 且国家为 "CN" 或 "USA" 的所有网站:

实例

SELECT * FROM Websites WHERE alexa > 15 AND (country='CN' OR country='USA');

点击查看所有 SQL 教程 文章: https://codercto.com/courses/l/29.html

查看所有标签

Distributed Algorithms: An Intuitive Approach

Distributed Algorithms: An Intuitive Approach

Wan Fokkink / MIT Press / 2018-2-2 / USD 48.00

The new edition of a guide to distributed algorithms that emphasizes examples and exercises rather than the intricacies of mathematical models. This book offers students and researchers a guide to ......一起来看看 《Distributed Algorithms: An Intuitive Approach》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码