freeCodeCamp/guide/chinese/sql/sql-or-operator/index.md

25 lines
812 B
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 or Operator
localeTitle: SQL或运算符
---
## SQL或运算符
您可以在`SELECT`语句的`WHERE`子句中使用`OR`运算符。当您想要选择满足`OR`语句中至少一个条件的记录时,可以使用它。
下面是一个示例它选择Person表中所有男性或名称为“Mary”的记录
```sql
SELECT Id, Name, DateOfBirth, Gender
FROM Person
WHERE Gender = M OR Name = Mary
```
您可以在`WHERE`子句中组合其他运算符(使用括号表示操作的顺序),如下例所示:
```sql
SELECT Id, Name, DateOfBirth, Gender
FROM Person
WHERE Gender = M AND (Name = Peter OR Name = John)
```
此示例选择Gender为“M”且Name为“Peter”的所有记录以及Gender为“M”且名称为“John”的记录。