部门表数据
insert into DEPT (deptno, dname, loc)
values (10, 'ACCOUNTING', 'NEW YORK');
insert into DEPT (deptno, dname, loc)
values (20, 'RESEARCH', 'DALLAS');
insert into DEPT (deptno, dname, loc)
values (30, 'SALES', 'CHICAGO');
insert into DEPT (deptno, dname, loc)
values (40, 'OPERATIONS', 'BOSTON');
![](https://img-blog.csdnimg.cn/20210331225945490.png)
员工表数据
insert into emp (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7369, 'SMITH', 'CLERK', 7902, '1980-12-17', 800, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7499, 'ALLEN', 'SALESMAN', 7698, '1981-02-20', 1600, 300, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7521, 'WARD', 'SALESMAN', 7698, '1981-02-22', 1250, 500, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7566, 'JONES', 'MANAGER', 7839, '1981-04-02', 2975, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7654, 'MARTIN', 'SALESMAN', 7698, '1981-09-28', 1250, 1400, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7698, 'BLAKE', 'MANAGER', 7839, '1981-05-01', 2850, null, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7782, 'CLARK', 'MANAGER', 7839, '1981-06-09', 2450, null, 10);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7788, 'SCOTT', 'ANALYST', 7566, '1987-04-19', 3000, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7839, 'KING', 'PRESIDENT', null, '1981-11-17', 5000, null, 10);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7844, 'TURNER', 'SALESMAN', 7698, '1981-09-08', 1500, 0, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7876, 'ADAMS', 'CLERK', 7788, '1987-05-23', 1100, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7900, 'JAMES', 'CLERK', 7698, '1981-12-03', 950, null, 30);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7902, 'FORD', 'ANALYST', 7566, '1981-12-03', 3000, null, 20);
insert into EMP (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (7934, 'MILLER', 'CLERK', 7782, '1982-01-23', 1300, null, 10);
![](https://img-blog.csdnimg.cn/20210331225720866.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dxaDEwMTEyMQ==,size_16,color_FFFFFF,t_70)
工资级别表数据
INSERT INTO salgrade VALUES (1,700,1200);
INSERT INTO salgrade VALUES (2,1201,1400);
INSERT INTO salgrade VALUES (3,1401,2000);
INSERT INTO salgrade VALUES (4,2001,3000);
![](https://img-blog.csdnimg.cn/20210331225753831.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dxaDEwMTEyMQ==,size_16,color_FFFFFF,t_70)
select distinct job from emp; //distinct去重
select ename,(sal+ifnull(comm,0))*12 as salary from emp;
select * from emp where sal>1500;
- 查询工资高于(等于)1500并且低于(等于)3000的所有员工信息
//方式一
select * from emp where sal between 1500 and 3000;
//方式二
select * from emp where sal>=1500 and sal<=3000;
select * from emp where comm is not null and comm!=0;
select * from emp where comm is null or comm=0;
select * from emp where sal>1500 and comm is not null and comm!=0;
- 查询工资不高于1500,同时不可以获得奖金的员工信息
select * from emp where sal<=1500 and comm is null;
//方式一:
select * from emp where hiredate like '1981%';
//方式二:
select * from emp where hiredate between '1981-01-01' and '1981-12-1';
select * from emp where ename='smith';
select * from emp where ename like '%s%';
select * from emp where ename like '_l';
//方式一
select * from emp where empno!=7369;
//方式二
select * from emp where empno<>7369;
- 查询员工编号在7369,7788,7900的员工信息
方式一:
select * from emp where empno=7369 or empno=7788 or empno=7900;
方式二:
select * from emp where empno in(7369,7788,7900);
- 查询出20部门的员工信息,查询出的信息按照工资由高到低排序,如果工资相同,按照入职日期由早到晚排序
select * from emp where deptno=20 order by sal desc,hiredate asc;