sql between 关键字简介


一、sql between关键字功能简介

between关键字功能:配合where子句,返回列值在between范围中的值
between关键字通常同and关键字一起配合使用,形成一个区间范围条件
between 关键字常用于 数值和日期区间数据的获取


二、 sql between语法及应用

2.1 语法简介

  select [列名1],[列名2],[列名3], ... from [表名] 
  where [列名] between [值1] and [值2]

2.2 举例应用

  
/*1 建表插入数据*/
create table A(keyId int primary key,info varchar(60), writeDate datetime)
insert into A values
(1,'a','2017-1-1'),(2,'b','2017-1-2'),(3,'c','2017-1-3'),
(11,'猫猫团','2017-2-1'),(12,'猫猫集','2017-2-2'),(13,'猫猫小','2017-2-3'),
(14,'猪','2017-2-3'),(15,'abcd','2017-2-3'),(16,'花猫狗','2017-2-3')
 
/*1 between 关键字应用*/
select  keyId,info,writeDate from A where keyId between 1 and 10 
  
/*2 between 关键字 中文区间应用 会根据首字符转换为ASCII码进行区间比较*/
select  keyId,info,writeDate from A where info  between '猫' and '你' 
 
truncate table A
drop table A 

相关阅读:
sql in 关键字简介
sql like 关键字简介及应用
sql top 关键字简介
sql delete 关键字简介
sql update 关键字简介
sql insert into 关键字简介及用法
sql order by 关键字用法
sql and or 关键字简介
sql where 关键字简介
sql select distinct top 关键字简介
sql select
sql简介
sql 删除重复数据
如果查询MSSQL中重复列(group by having count)