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);
![27f7f1e9fee79d84918956a89fe891ab.png](https://i-blog.csdnimg.cn/blog_migrate/7be248035211af9ce8b73545b13b70cf.jpeg)
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;
![05279ebd7206ca73ce489b8d18ccfaba.png](https://i-blog.csdnimg.cn/blog_migrate/cf81c0bd322b6996251bc633e7e5c2c9.jpeg)
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;
![3999eaa890d33f580d1f2f434e558d77.png](https://i-blog.csdnimg.cn/blog_migrate/d4edae0e0bf98bbd7ec6d2a9ebc88fef.jpeg)