七、模糊查询
1、模糊查询常用的运算符号
like between and in is null is not null
2、案例:
案例一(between and的使用):查询工资在4K-9K的员工信息
select *
from emp
where salary between 4000 and 9000;
注意:包含了临界值,上面的例子就包含了4000和9000
案例二( in的使用):查询员工的工种编号是ID_PROG,AD_VP,AD_PRES中的一个员工名和工种编号
select last_name,job_id
from emp
where job_id in('ID_PROG','AD_VP','AD_PRES');
注意:in列表的值必须保持统一;类似闭区间:如in(200,400),包括了200和400
案例三(is null的使用):查询无奖金的员工名
select last_name
from emp
where commision_pct is null;
注意:在数据库中null不是一个值,代表的是什么都没有,为空;
不能用“=”来衡量即commision_pct = null (错误),必须使用is null 或者is not null
案例四(like的使用):查询员工名中包含字符e的员工信息
select *
from emp
where name like '%e%'; //%表示任意多个字符,包含0个字符
案例五:查询以字符k开头的员工信息
select *
from emp
where name like 'k%';
案例六:查询员工名中第三个字符为n,第五个字符为l的员工信息
select *
from employees
where last_name like '__n_l%'; // “_” 表示任意单个字符
案例七:查询员工名中第二个字符是_的员工名
select last_name
from employees
where last_name like '_\_%'; //经常用 这里是用的是转义字符,但是也可以用其他字母来定义转义字符 last_name like '_$_%' escape '$';

浙公网安备 33010602011771号