使用BETWEEN
运算符将一个值与一系列值进行匹配
value BETWEEN low AND high
如果value
在low
和high
之间,则返回TRUE
,否则返回FALSE
。
BETWEEN
可以使用大于等于和小于等于运算符,但是不能使用LIKE
运算符。
value >= low and value <= high
检查是否超出范围,可以使用NOT
和BETWEEN
组合运算符。
value NOT BETWEEN low AND high
等价于
value < low OR value > high
使用BETWEEN
查询金额是否在 8 和 9 之间。
SELECT
customer_id,
payment_id,
amount
FROM
payment
WHERE
amount BETWEEN 8 AND 9;
查询金额不在 8 和 9 之间。
SELECT
customer_id,
payment_id,
amount
FROM
payment
WHERE
amount NOT BETWEEN 8 AND 9;