#案例1,查询工资>12000的员工信息SELECT*FROM employees WHERE salary>12000;#案例2,查询部门编号不等于90号的员工名和部门编号SELECT last_name,
department_id
FROM
employees
WHERE
department_id<>90;
二 按逻辑表达式筛选
#案例1: 查询工资在z在10000到20000之间的员工名,工资以及奖金SELECT
last_name,
salary,
commission_pct
FROM
employees
WHERE
salary>=10000AND salary <=20000;#案例2: 查询部门编号不是在90到110之间,或者工资高于15000的员工信息SELECT*FROM employees
WHERENOT(department_id>=90AND department_id<=110)OR salary>15000;
三,模糊查询
/*
LIKE
1.一般和通配符搭配使用 % 任意多个字符,包含0个字符
*/# LIKE # 案例1: 查询员工名中包含字符a的员工信息SELECT*FROM
employees
WHERE
last_name LIKE'%a%';# 案例2; 查询员工名中第三个字符为e,第五个字符为a的员工名称和工资SELECT
last_name,
salary
FROM
employees
WHERE
last_name LIKE'__n_1%';#案例3 查询员工名中第二个字符为_的员工名# @为转义字符 ESCAPESELECT
last_name
FROM
employees
WHERE
last_name LIKE'_@_%'ESCAPE'@';
# between and/*
使用between and 可以提高语句的简洁度
包含临界值
两个临界值不要调换顺序
*/#案例一:查询员工编号在100到120之间的员工信息SELECT*FROM
employees
WHERE
employee_id>=100AND employee_id<=120;#方式二SELECT*FROM
employees
WHERE
employee_id BETWEEN100AND120;
# in/*
判断某字段的值是否属于in列表中的某一项
*/SELECT
last_name,
job_id
FROM
employees
WHERE
job_id IN('IT_PROG','AD_VP','AD_PRES');# is null;#案列1:查询没有奖金的员工名和奖金率SELECT
last_name,
commission_pct
FROM
employees
WHERE
commission_pct ISNULL;#案列2:查询有奖金的员工名和奖金率SELECT
last_name,
commission_pct
FROM
employees
WHERE
commission_pct ISNOTNULL;
#安全等于 <=>/*
即可以判断NULL值,又可以判断普通的数值,可读性较低
*/#案例1SELECT
last_name,
salary
FROM
employees
WHERE
salary <=>12000;#2.查询员工号为176的员工的姓名和部门号和年薪SELECT
last_name,
deparment_id,
salary*12*(1+IFNULL(commission_pct,0))AS 年薪
FROM
employees;