本文概述
SQL Server BETWEEN运算符用于在SELECT, INSERT, UPDATE或DELETE语句中检索指定范围内的值。
句法:
expression BETWEEN value1 AND value2;
参数说明
表达式:指定列或计算。
value1和value2:这些值指定表达式用于比较的包含范围。
具有数值的BETWEEN运算符
从ID在7到13之间的” Employees”表中检索所有雇员。
SELECT *
FROM [srcmini].[dbo].[Employees]
WHERE id BETWEEN 7 AND 13;
输出
Or
SELECT *
FROM [srcmini].[dbo].[Employees]
WHERE id >= 7
AND id <= 13;
输出
带NOT运算符的BETWEEN运算符
从表” Employees”中检索所有满足以下BETWEEN NOT条件的员工。
SELECT *
FROM [srcmini].[dbo].[Employees]
WHERE id NOT BETWEEN 7 AND 11;
输出
Or
SELECT *
FROM [srcmini].[dbo].[Employees]
WHERE id < 7
OR id > 11;
输出
评论前必须登录!
注册