BETWEEN 操作符在 WHERE 子句中使用,作用是选取介于两个值之间的数据范围。
BETWEEN 操作符
操作符 BETWEEN ... AND 会选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。
SQL BETWEEN 语法
SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
原始的表 (在实例中使用:)
Persons 表:
Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing
4 Gates Bill Xuanwumen 10 Beijing
BETWEEN 操作符实例
如需以字母顺序显示介于 "Adams"(包括)和 "Carter"(不包括)之间的人,请使用下面的 SQL:
SELECT * FROM Persons
WHERE LastName
BETWEEN 'Adams' AND 'Carter'
结果集:
Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York |