个性化阅读
专注于IT技术分析

SQL Server BETWEEN运算符示例详解

本文概述

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;

输出

SQL Server BETWEEN运算符

Or

SELECT *
FROM [srcmini].[dbo].[Employees]
WHERE id >= 7
AND id <= 13;

输出

SQL Server BETWEEN运算符

带NOT运算符的BETWEEN运算符

从表” Employees”中检索所有满足以下BETWEEN NOT条件的员工。

SELECT *
FROM [srcmini].[dbo].[Employees]
WHERE id NOT BETWEEN 7 AND 11;

输出

SQL Server BETWEEN运算符

Or

SELECT *
FROM [srcmini].[dbo].[Employees]
WHERE id < 7
OR id > 11;

输出

SQL Server BETWEEN运算符 4
赞(0)
未经允许不得转载:srcmini » SQL Server BETWEEN运算符示例详解

评论 抢沙发

评论前必须登录!