BETWEEN 操作符在 WHERE 子句中使用,作用是选取介于两个值之间的数据范围。
操作符 BETWEEN ... AND 会选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。
注意:在Oracle中,BETWEEN ... AND 包含边界。
语法:
select column_name(s)
from table_name
where column_name
between value1 and value2;
例:
1. 查询employees表中salary在2600到2800之间的员工姓名
SQL> select last_name,salary from employees where salary between 2600 and 2800;
LAST_NAME SALARY
------------------------- ----------
OConnell 2600
Grant 2600
Tobias 2800
Himuro 2600
Mikkilineni 2700
Atkinson 2800
Seo 2700
Matos 2600
Geoni 2800
Jones 2800
10 rows selected.
2. 查询employees表中salary不在2300到17000之间的员工姓名
SQL> select last_name,salary from employees where salary not between 2300 and 17000;
LAST_NAME SALARY
------------------------- ----------
King 24000
Markle 2200
Olson 2100
Philtanker 2200