7.在WHERE中使用in和not in条件
字段 in (值1,值2,值3...):字段值在指定的集合元素中
//查询10,20,30,40这些部门的员工信息
select empno,ename
from emp
where deptno=10 or deptno=20
or deptno=30 or deptno=40;
//采用in实现
select empno,ename,deptno
from emp
where deptno in (10,20,30,40);
//查询10,20,30,40部门之外的员工信息
select empno,ename,deptno
from emp
where deptno not in (10,20,30,40);
//查询MANAGER和ANALYST职位的员工信息
select empno,ename,job
from emp
where job in (‘MANAGER‘,‘ANALYST‘);
时间: 2024-10-19 14:45:45