sql 运算符between与大于小于

between值 and 值 运算符用于选取介于两个值之间的数据范围内的值,常与where一块使用
between运算符选择给定范围内的值。值可以是数字,文本或日期。
使用between的时候会与and 一块连用,表示在啥啥之间,是不是让我们想起来大于某个小于某个
注意:
  在某些数据库中,BETWEEN 选取介于两个值之间但不包括两个测试值的字段。
  在某些数据库中,BETWEEN 选取介于两个值之间且包括两个测试值的字段。
  在某些数据库中,BETWEEN 选取介于两个值之间且包括第一个测试值但不包括最后一个测试值的字段。
语法:

select * from 表名 where 字段 between 字段对应的值 and 字段对应的值

建个表弄点数据
在这里插入图片描述
运算符 between 和 < ,>,<= ,>= 一块使用
注意:查询数字的时候是左右都包含哦,这是sqlserver 数据库
在这里插入图片描述
运算符 not between 和 !< ,!>一块使用
语法:

select * from 表名 where not  字段 between 字段对应的值  and  字段对应的值

在这里插入图片描述
运算符between 和 in 一块使用
在这里插入图片描述
进行查询日期格式的时候和查询数字一样,一般在实际的项目中用于查询这个日期在这个区间中
tbCreateTimeEnd和tbCreateTimeStart 前段传来的值

        {//时间范围
            DateTime d1 = DateTime.Parse("1900-01-01 00:00:00");
            DateTime d2 = DateTime.Parse("2900-01-01 00:00:00");
            if (this.tbCreateTimeStart.Value != string.Empty)
            {
                try
                {
                    d1 = Convert.ToDateTime(this.tbCreateTimeStart.Value);
                }
                catch
                {
                    d1 = d2;
                }
            }
            if (this.tbCreateTimeEnd.Value != string.Empty)
            {
                try
                {
                    d2 = Convert.ToDateTime(this.tbCreateTimeEnd.Value);
                }
                catch
                {
                    d2 = d1;
                }
            }
            strSql += " and CreateTime between '" + d1.ToString("yyyy-MM-dd 00:00:00") + "' and '" + d2.ToString("yyyy-MM-dd 23:59:59") + "'";
        }

查询文本和字符串的时候也可以查
在这里插入图片描述
在这里插入图片描述

-- between 字段对应值 and  字段对应值
--  语法: select * from 表名 where 字段 between 字段对应的值 and 字段对应的值
-- 查询年龄在1020 之间的数据   左右都包含
select * from test where Age between 11 and 22
-- 查询年龄在1020 之间的数据
select * from test where Age<=22  and Age >10


-- 查询年龄不在1020 之间的数据  包括 1120
select * from test where not Age between 12 and 22 
-- 使用运算符 !> 等 查询查询年龄不在1020 之间的数据
select * from test where Age !>11  or Age !<23

--  查询年龄在1122 之间 不包含 1122
select * from test where (Age between 11 and 22) and not Age in (11,22)


-- 根据字母排序进行查询  m 不包含  不会查询汉字
select * from test where Name between 'b' and 'm'

-- 查询汉字
select * from test where Name between '大乔' and '小乔'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值