1. Prepare
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…
Comparing whether the data in a specified interval within the closed range
. 1 - Query sal data between 1500 and 3000 (including 1500 and 3000) 2 the SELECT * the FROM EMP the WHERE sal > = 1500 the AND sal <= 3000 ; . 3 - equivalent . 4 the SELECT * the FROM EMP the WHERE sal the BETWEEN 1500 the AND 3000 ;
3.NOT BETWEEN…AND…
A comparison whether the data is not within the range specified closed interval
. 1 - Query sal less than 1500 or more than 3000 data (not including 1500 and 3000) 2 the SELECT * the FROM EMP the WHERE sal < 1500 OR sal > 3000 ; . 3 - equivalent . 4 the SELECT * the FROM EMP the WHERE sal the NOT the BETWEEN 1500 the AND 3000 ;