1.准备
1 CREATE DATABASE mahaiwuji; 2 USE mahaiwuji; 3 4 CREATE TABLE emp 5 ( 6 empno INT PRIMARY KEY, 7 ename VARCHAR(10), 8 sal INT 9 ) ENGINE = INNODB DEFAULT CHARSET = utf8; 10 11 INSERT INTO emp VALUES (1,'smith',2800); 12 INSERT INTO emp VALUES (2,'allen',1500); 13 INSERT INTO emp VALUES (3,'ward',3500); 14 INSERT INTO emp VALUES (4,'jones',1300); 15 INSERT INTO emp VALUES (5,'martin',1600); 16 INSERT INTO emp VALUES (6,'blake',3000);
2.BETWEEN…AND…
比较一个数据是否在指定的闭区间范围内
1 -- 查询sal在1500和3000之间的数据(包括1500和3000) 2 SELECT * FROM emp WHERE sal >= 1500 AND sal <= 3000; 3 -- 等价于 4 SELECT * FROM emp WHERE sal BETWEEN 1500 AND 3000;
3.NOT BETWEEN…AND…
比较一个数据是否不在指定的闭区间范围内
1 -- 查询sal小于1500或者大于3000的数据(不包括1500和3000) 2 SELECT * FROM emp WHERE sal < 1500 OR sal > 3000; 3 -- 等价于 4 SELECT * FROM emp WHERE sal NOT BETWEEN 1500 AND 3000;
来源:https://www.cnblogs.com/mahaiwuji/p/12649944.html