龙空技术网

15.MySQL中的BETWEEN(在某个范围)

码海无际 110

前言:

如今看官们对“mysqlbetweenand边界”大体比较着重,看官们都想要分析一些“mysqlbetweenand边界”的相关资讯。那么小编同时在网络上收集了一些对于“mysqlbetweenand边界””的相关内容,希望小伙伴们能喜欢,你们快快来学习一下吧!

1.准备

CREATE DATABASE mahaiwuji;USE mahaiwuji;CREATE TABLE emp(    empno INT PRIMARY KEY,    ename VARCHAR(10),    sal INT) ENGINE = INNODB DEFAULT CHARSET = utf8;INSERT INTO emp VALUES (1,'smith',2800);INSERT INTO emp VALUES (2,'allen',1500);INSERT INTO emp VALUES (3,'ward',3500);INSERT INTO emp VALUES (4,'jones',1300);INSERT INTO emp VALUES (5,'martin',1600);INSERT INTO emp VALUES (6,'blake',3000);
2.BETWEEN…AND…

比较一个数据是否在指定的闭区间范围内

-- 查询sal在1500和3000之间的数据(包括1500和3000)SELECT * FROM emp WHERE sal >= 1500 AND sal <= 3000;-- 等价于SELECT * FROM emp WHERE sal BETWEEN 1500 AND 3000;
3.NOT BETWEEN…AND…

比较一个数据是否不在指定的闭区间范围内

-- 查询sal小于1500或者大于3000的数据(不包括1500和3000)SELECT * FROM emp WHERE sal < 1500 OR sal > 3000;-- 等价于SELECT * FROM emp WHERE sal NOT BETWEEN 1500 AND 3000;

标签: #mysqlbetweenand边界 #mysqlbetween边界 #mysql中between