zoukankan      html  css  js  c++  java
  • 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 字段对应的值
    -- 查询年龄在10 到20 之间的数据   左右都包含
    select * from test where Age between 11 and 22
    -- 查询年龄在10 到20 之间的数据
    select * from test where Age<=22  and Age >10
    
    
    -- 查询年龄不在10 到20 之间的数据  包括 11和20
    select * from test where not Age between 12 and 22 
    -- 使用运算符 !> 等 查询查询年龄不在10 到20 之间的数据
    select * from test where Age !>11  or Age !<23
    
    --  查询年龄在11到22 之间 不包含 11和22
    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 '小乔'
  • 相关阅读:
    Paxos算法简单陈述
    二段式提交和三段式提交
    Guava包学习--Hash
    JedisPool无法获得资源问题
    有料面试题之--Object里面的方法
    Spring常用jar包的功能
    线上日志分析与其他一些脚本
    Flutter-漸變色按鈕
    Flutter-自定義圖標或者選擇框
    Flutter-自定義圖片圖標
  • 原文地址:https://www.cnblogs.com/obge/p/11647094.html
Copyright © 2011-2022 走看看