一、语法
select 查询列表
from 表名
where 筛选条件
二、筛选条件的分类
1、简单条件运算符
> < = <> != >= <= <=>安全等于
2、逻辑运算符
&& and
|| or
! not
例子:SELECT * FROM employees WHERE NOT (department_id >= 90 AND department_id <= 110) OR salary > 15000;
3、模糊查询
like:一般搭配通配符使用,可以判断字符型或数值型
通配符:%任意多个字符,_任意单个字符
eg:查询员工名中包含字符a的员工信息
select * from employees where last_name like '%a%';
between and
eg:查询员工编号在100到120之间的员工信息
select * from employees where employee_id between 100 and 120;
in(判断某字段的值是否属于in列表中的某一项)
eg:查询员工的工种名编号 IT_PROG,AD_VP,AD_PRES中的一个员工名和工种编号
select last_name,job_id from employees
where job_id in('IT_PROT','AD_VP','AD_PRES')
is null /is not null:用于判断null值
eg:查询没有奖金的员工名和奖金率
select last_name,commission_pct from employees where commission_pct is null;
is null PK <=>
普通类型的数值 null值 可读性
is null × √ √
<=> √
安全等于 <=>
eg:查询没有奖金的员工名和奖金率
select last_name,commission_pct from employees where commission_pct <=> null;
eg:查询工资为12000的员工信息
select last_name,salary from employees
where salary <=> 12000;