-- 四、查询某字段的值是否属于指定的列表之内 in/not in #案例1:查询部门编号是30/50/90的员工名、部门编号 #案例2:查询工种编号不是SH_CLERK或IT_PROG的员工信息
时间: 2023-06-17 17:05:48 浏览: 96
案例1:
查询部门编号是30/50/90的员工名、部门编号
```sql
SELECT ename, deptno FROM emp WHERE deptno IN(30,50,90);
```
结果示例:
| ename | deptno |
| ------ | ------ |
| ALLEN | 30 |
| WARD | 30 |
| MARTIN | 30 |
| BLAKE | 30 |
| CLARK | 10 |
| JONES | 20 |
| SCOTT | 20 |
| KING | 10 |
| TURNER | 30 |
| ADAMS | 20 |
| JAMES | 30 |
| FORD | 20 |
| MILLER | 10 |
案例2:
查询工种编号不是SH_CLERK或IT_PROG的员工信息
```sql
SELECT * FROM emp WHERE job NOT IN ('SH_CLERK','IT_PROG');
```
结果示例:
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
| ----- | ------- | ----------| ---- | ----------| ----- | ---- | ------ |
| 7369 | SMITH | CLERK | 7902 | 1980-12-17| 800.0 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20| 1600.0| 300.0| 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22| 1250.0| 500.0| 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02| 2975.0| NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28| 1250.0| 1400.| 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01| 2850.0| NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09| 2450.0| NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09| 3000.0| NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17| 5000.0| NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08| 1500.0| 0.0 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12| 1100.0| NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03| 950.0 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03| 3000.0| NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23| 1300.0| NULL | 10 |
阅读全文