- 类别:
[ NOT ] BETWEEN¶
当输入表达式(数值或字符串)在指定的下限和上限范围内时,返回 TRUE
。
语法¶
<expr> [ NOT ] BETWEEN <lower_bound> AND <upper_bound>
使用说明¶
expr BETWEEN lower_bound AND upper_bound
等效于:samp:{expr} >= {lower_bound} AND {expr} <= {upper_bound}。指定的上限必须大于下限。
排序规则详细信息¶
表达式 A BETWEEN X AND Y
等效于 A >= X AND A <= Y
。用于比较 X
和 Y
的排序规则是独立的,不需要完全相同,但两者都需要与 A
的排序规则兼容。
示例¶
下列是将 BETWEEN 与数值和字符串值结合使用的几个简单示例:
SELECT 'true' WHERE 1 BETWEEN 0 AND 10; +--------+ | 'TRUE' | |--------| | true | +--------+SELECT 'true' WHERE 1.35 BETWEEN 1 AND 2; +--------+ | 'TRUE' | |--------| | true | +--------+SELECT 'true' WHERE 'the' BETWEEN 'that' AND 'then'; +--------+ | 'TRUE' | |--------| | true | +--------+
下列示例将 COLLATE
与 BETWEEN
结合使用:
SELECT 'm' BETWEEN COLLATE('A', 'lower') AND COLLATE('Z', 'lower'); +-------------------------------------------------------------+ | 'M' BETWEEN COLLATE('A', 'LOWER') AND COLLATE('Z', 'LOWER') | |-------------------------------------------------------------| | True | +-------------------------------------------------------------+ SELECT COLLATE('m', 'upper') BETWEEN 'A' AND 'Z'; +-------------------------------------------+ | COLLATE('M', 'UPPER') BETWEEN 'A' AND 'Z' | |-------------------------------------------| | True | +-------------------------------------------+