SQL基础(一六)--- 范围值检测

来源:互联网 发布:知周科技是否准备上市 编辑:程序博客网 时间:2024/04/28 19:35

查询年龄在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 setmysql> 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 setmysql> 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




0 0