查询年龄在23~27岁的员工信息:
mysql> select * from t_employee
-> where fage>=23 and fage<=27;
+----------+-------+------+---------+
| fnumber | fname | fage | fsalary |
+----------+-------+------+---------+
| DEV001 | Tom | 25 | 8300 |
| HR001 | Jane | 23 | 2200.88 |
| HR002 | Tina | 25 | 5200.36 |
| IT002 | NULL | 27 | 2800 |
| SALES001 | John | 23 | 5000 |
+----------+-------+------+---------+
5 rows in set
mysql> select * from t_employee
-> where fage between 23 and 27;
+----------+-------+------+---------+
| fnumber | fname | fage | fsalary |
+----------+-------+------+---------+
| DEV001 | Tom | 25 | 8300 |
| HR001 | Jane | 23 | 2200.88 |
| HR002 | Tina | 25 | 5200.36 |
| IT002 | NULL | 27 | 2800 |
| SALES001 | John | 23 | 5000 |
+----------+-------+------+---------+
5 rows in set
mysql> select * from t_employee
-> where fage in(23,24,25,26,27);
+----------+-------+------+---------+
| fnumber | fname | fage | fsalary |
+----------+-------+------+---------+
| DEV001 | Tom | 25 | 8300 |
| HR001 | Jane | 23 | 2200.88 |
| HR002 | Tina | 25 | 5200.36 |
| IT002 | NULL | 27 | 2800 |
| SALES001 | John | 23 | 5000 |
+----------+-------+------+---------+
5 rows in set
查询工资在2000~3000和5000~8000的员工信息:
mysql> select * from t_employee
-> where (fsalary between 2000 and 3000) or (fsalary between 5000 and 8000);
+----------+-------+------+---------+
| fnumber | fname | fage | fsalary |
+----------+-------+------+---------+
| DEV002 | Jerry | 28 | 2300.8 |
| HR001 | Jane | 23 | 2200.88 |
| HR002 | Tina | 25 | 5200.36 |
| IT002 | NULL | 27 | 2800 |
| SALES001 | John | 23 | 5000 |
| SALES002 | Kerry | 28 | 6200 |
+----------+-------+------+---------+
6 rows in set