#进阶2:条件查询 /* 语法: SELECT 查询列表 FROM 表名 WHERE 筛选条件 分类: 1、按条件表达式筛选:> < = != <> >= <= 2、按逻辑表达式筛选:&& || ! AND OR NOT 3、模糊查询:LIKE, BETWEEN AND, IN, IS NULL */ USE myemployees; #1、按条件表达式筛选 #案例1:查询工资大于12000的员工信息 SELECT * FROM employees WHERE salary > 12000; #2、按逻辑表达式筛选 #案例2:工资在10000到20000之间的员工名、工资以及奖金 SELECT Concat(last_name, ' ', first_name) AS "name", salary, commission_pct FROM employees WHERE salary >= 10000 AND salary <= 20000; #3、模糊查询 #案例3:查询员工名中包含字符a的员工信息 # % 通配符,任意多个任意字符 # _ 通配符,单个任意字符 SELECT * FROM employees WHERE last_name LIKE '%a%'; SELECT last_name, salary FROM employees WHERE last_name LIKE '__n_l%'; #案例4:查询员工名中第二个字符为_的员工名 #转义:\ SELECT last_name FROM employees WHERE last_name LIKE '_\_%'; #回顾案例2:工资在10000到20000之间的员工名、工资以及奖金 SELECT Concat(last_name, ' ', first_name) AS "name", salary, commission_pct FROM employees WHERE salary BETWEEN 10000 AND 20000; #案例5:查询员工的工种名 #IN的类型要相同 SELECT job_id FROM employees WHERE job_id IN ('IT_PROG', 'AD_VP', 'AD_PRES'); #案例6:没有奖金的员工 #IS NOT NULL, IS NULL SELECT last_name, commission_pct FROM employees WHERE commission_pct IS NULL; #安全等于 <=>,本质就是等于 #可读性略低 SELECT last_name, commission_pct FROM employees WHERE commission_pct <=> NULL; SELECT last_name, salary FROM employees WHERE salary <=> 12000;