表条件查询:
/*
语法:
SELECT 查询列表 FROM 表名 WHERE 筛选条件;
分类:
一、按条件表达式筛选:
= 等于,<> 不等于,!= 不等于,< 小于,> 大于,<= 小于等于,>= 大于等于
二、按逻辑表达式刷选:
&& || !
and or not
三、模糊查询:
like, between and, in,is null
*/
模糊查询:
like:通常和通配符结合使用(%表示任意多个字符,包含0,_表示单个任意字符)
案例1:查询姓名包含a的员工信息
select * from employees where last_name = '%a%';
案例2:查询姓名第三个字母为e第五个字母为a的员工姓名和工资
select last_name,salary from employees where last_name = '__e_a%';
案例2:查询姓名第二个字母为_的员工姓名
select last_name from employees where last_name = '_\_%';
或则自己定义一个转义字符
select last_name from employees where last_name = '_$_%' escape '$';
between and:大于等于左边小于等于右边,不可以交换顺序
案例1:员工编号在100到120的员工信息(包含边界值)
select * from employees where employee_id between 100 and 120;
in:选择中不支持通配符,必须完整
案例1:查询员工的工种编号是ad_vp,ad_pres,it_prog 中的一个的员工姓名和工种编号
select last_name,job_id from employees where job_id in ('ad_vp','ad_pres','it_prog');
is null:
select last_name from employees where commission_pct is null;