sql语句中的in用法示例
IN运算符定义 (The IN Operator defined)
The IN
operator is used in a WHERE
or HAVING
(as part of the GROUP BY
) to limit the selected rows to the items “IN” a list.
在WHERE
或HAVING
(作为GROUP BY
一部分)使用IN
运算符将所选行限制为列表中的“ IN”项。
Here is the current full student list to compare to the WHERE
clause result set:
这是当前的完整学生列表,可与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)
Rows will be presented that have an SAT score in this list (1000, 2400):
将显示此列表中具有SAT分数的行(1000、2400):
select studentID, FullName, sat_score, rcd_updated
from student
where sat_score in (1000, 2400);
+-----------+------------------------+-----------+---------------------+
| studentID | FullName | sat_score | rcd_updated |
+-----------+------------------------+-----------+---------------------+
| 3 | Spencer Pautier | 1000 | 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 |
+-----------+------------------------+-----------+---------------------+
4 rows in set (0.00 sec)
翻译自: https://www.freecodecamp.org/news/the-sql-in-statement-explained-with-example-syntax/
sql语句中的in用法示例