SQL——关于bjpowernode.sql的33道经典例题之1-17

news2024/11/22 19:39:40

目录

1 查询每个部门最高薪水的人员名称

2 查询哪些人的薪水在部门平均薪水之上

3 查询每个部门的平均薪水等级

3.1 每个部门的平均薪水的等级 

3.2 每个部门的平均的薪水等级

4 查询最高薪水(不用max函数)

5 查询平均薪水最高的部门的部门编号

6 查询平均薪水最高的部门的部门名称

7 查询平均薪水的等级最低的部门的部门名称

8 查询比普通员工的最高薪水还要高的经理人姓名

9 查询薪水最高的前五名员工

10 查询薪水最高的第6-10名员工

11 查询最后入职的5名员工

12 查询每个薪水等级有多少员工

13 列出所有员工及领导名字

14 受雇日期早于其直接上级的所有员工编号、姓名、部门名称

15 列出部门名称和员工信息,同时列出没有员工的部门

16 列出至少5个员工的所有部门

17 列出薪水比“SMITH”多的所有员工信息


数据代码在文末。 


1 查询每个部门最高薪水人员名称

# (1)求出每个部门的最高薪水
select e.deptno,max(e.sal) maxsal from emp e
group by e.deptno; 
+--------+---------+
| deptno | maxsal  |
+--------+---------+
|     20 | 3000.00 |
|     30 | 2850.00 |
|     10 | 5000.00 |
+--------+---------+

# (2)将以上表当作一个临时表t,多表连接(join...on...)
select e.deptno,e.ename,t.maxsal,e.sal
from (select e.deptno,max(e.sal) as maxsal from emp e group by e.deptno) t
join emp e on e.deptno=t.deptno
where t.maxsal=e.sal
order by e.deptno;
+--------+-------+---------+---------+
| deptno | ename | maxsal  | sal     |
+--------+-------+---------+---------+
|     10 | KING  | 5000.00 | 5000.00 |
|     20 | SCOTT | 3000.00 | 3000.00 |
|     20 | FORD  | 3000.00 | 3000.00 |
|     30 | BLAKE | 2850.00 | 2850.00 |
+--------+-------+---------+---------+

2 查询哪些人的薪水在部门平均薪水之上

# (1)部门平均薪水
select e.deptno,avg(sal) avgsal from emp e 
group by deptno; 
+--------+-------------+
| deptno | avgsal     |
+--------+-------------+
|     20 | 2175.000000 |
|     30 | 1566.666667 |
|     10 | 2916.666667 |
+--------+-------------+

# (2)当作临时表t,多表连接(join...on...)
select t.deptno,e.ename
from (select e.deptno,avg(sal) avgsal from emp e group by e.deptno) t
join emp e on e.deptno=t.deptno
where e.sal>t.avgsal
order by t.deptno;
+--------+-------+
| deptno | ename |
+--------+-------+
|     10 | KING  |
|     20 | JONES |
|     20 | SCOTT |
|     20 | FORD  |
|     30 | ALLEN |
|     30 | BLAKE |
+--------+-------+

3 查询每个部门平均薪水等级

3.1 每个部门平均薪水等级 

# (1)部门的平均薪水
select e.deptno,avg(e.sal) as avgsal
from emp e
group by e.deptno;
+--------+-------------+
| deptno | avgsal      |
+--------+-------------+
|     20 | 2175.000000 |
|     30 | 1566.666667 |
|     10 | 2916.666667 |
+--------+-------------+

#(2)部门的薪水等级
select * from salgrade;
+-------+-------+-------+
| GRADE | LOSAL | HISAL |
+-------+-------+-------+
|     1 |   700 |  1200 |
|     2 |  1201 |  1400 |
|     3 |  1401 |  2000 |
|     4 |  2001 |  3000 |
|     5 |  3001 |  9999 |
+-------+-------+-------+

# (3)将临时表t与表salgrade进行连接,查询平均薪水在哪个等级范围中
select t.deptno,s.grade
from (select e.deptno,avg(e.sal) as avgsal from emp e group by e.deptno) t
join salgrade s
on t.avgsal between s.losal and s.hisal
order by t.deptno;
+--------+-------+
| deptno | grade |
+--------+-------+
|     10 |     4 |
|     20 |     4 |
|     30 |     3 |
+--------+-------+

3.2 每个部门的平均薪水等级

# (1)查询部门每个人的薪水等级在哪个等级范围中
select e.deptno,e.ename,s.grade
from emp e
join salgrade s
on e.sal between s.losal and s.hisal
order by e.deptno;
+--------+--------+-------+
| deptno | ename  | grade |
+--------+--------+-------+
|     10 | CLARK  |     4 |
|     10 | KING   |     5 |
|     10 | MILLER |     2 |
|     20 | SMITH  |     1 |
|     20 | JONES  |     4 |
|     20 | SCOTT  |     4 |
|     20 | ADAMS  |     1 |
|     20 | FORD   |     4 |
|     30 | ALLEN  |     3 |
|     30 | WARD   |     2 |
|     30 | MARTIN |     2 |
|     30 | BLAKE  |     4 |
|     30 | TURNER |     3 |
|     30 | JAMES  |     1 |
+--------+--------+-------+

# (2)将临时表t按每个部门的等级进行平均
select t.deptno,avg(t.grade) as avgGrade
from (select e.deptno,e.ename,s.grade from emp e 
    join salgrade s on e.sal between s.losal and s.hisal order by e.deptno) t
group by t.deptno;
+--------+----------+
| deptno | avgGrade |
+--------+----------+
|     20 |   2.8000 |
|     30 |   2.5000 |
|     10 |   3.6667 |
+--------+----------+

4 查询最高薪水(不用max函数)

# 第一种方法
select sal from emp
order by sal desc
limit 1;
+---------+
| sal     |
+---------+
| 5000.00 |
+---------+

# 第二种方法
# (1)将两张一样的表进行比较,并且清除重复值
select distinct a.sal
from emp a
join emp b
on a.sal<b.sal;
+---------+
| sal     |
+---------+
| 1300.00 |
|  950.00 |
| 1100.00 |
| 1500.00 |
| 1250.00 |
|  800.00 |
| 2450.00 |
| 2850.00 |
| 1600.00 |
| 2975.00 |
| 3000.00 |
+---------+

# (2)选取除上表以外的最大值
select sal 
from emp 
where sal not in
(select distinct a.sal from emp a join emp b on a.sal<b.sal);
+---------+
| sal     |
+---------+
| 5000.00 |
+---------+

5 查询平均薪水最高的部门部门编号

# (1)每个部门的平均薪水
select e.deptno,avg(sal) avgsal
from emp e
group by e.deptno
order by e.deptno;
+--------+-------------+
| deptno | avgsal      |
+--------+-------------+
|     10 | 2916.666667 |
|     20 | 2175.000000 |
|     30 | 1566.666667 |
+--------+-------------+

# (2)临时表t中查询最高平均薪水
#(select中加入t.deptno,则会出错,因为会出现所有deptno,而最高只有一个平均薪水)
select max(t.avgsal) maxavgsal
from (select e.deptno,avg(sal) avgsal from emp e group by e.deptno) t;
+-------------+
| maxavgsal   |
+-------------+
| 2916.666667 |
+-------------+

# (3)使用having语句过滤
select e.deptno,avg(e.sal) as avgsal
from emp e 
group by e.deptno
having avgsal=(select max(t.avgsal) maxavgsal 
                from (select e.deptno,avg(sal) avgsal from emp e group by e.deptno) t);
+--------+-------------+
| deptno | avgsal      |
+--------+-------------+
|     10 | 2916.666667 |
+--------+-------------+

6 查询平均薪水最高的部门部门名称

# 将上一题作为临时表f,连接dept表 
select d.deptno,d.dname,f.avgsal
from (select e.deptno,avg(e.sal) as avgsal
        from emp e 
        group by e.deptno
        having avgsal=(select max(t.avgsal) maxavgsal 
                from (select e.deptno,avg(sal) avgsal from emp e group by e.deptno) t)) f
join dept d
on d.deptno=f.deptno;
+--------+------------+-------------+
| deptno | dname      | avgsal      |
+--------+------------+-------------+
|     10 | ACCOUNTING | 2916.666667 |
+--------+------------+-------------+

# 在having语句添加子查询,先将emp表与dept表先连接,再确定最高薪水
select e.deptno,d.dname,avg(e.sal) avgsal
from emp e
join dept d
on e.deptno=d.deptno
group by e.deptno,d.dname
having avgsal=(select max(t.avgsal) maxavgsal 
                from (select e.deptno,avg(sal) avgsal from emp e group by e.deptno) t);
+--------+------------+-------------+
| deptno | dname      | avgsal      |
+--------+------------+-------------+
|     10 | ACCOUNTING | 2916.666667 |
+--------+------------+-------------+

7 查询平均薪水等级最低部门部门名称

# (1)每部门平均薪水的等级
select t.deptno,t.dname,s.grade
from (select e.deptno,d.dname,avg(sal) avgsal 
        from emp e join dept d on e.deptno=d.deptno
        group by deptno) t
join salgrade s 
on t.avgsal between s.losal and s.hisal;
+--------+------------+-------+
| deptno | dname      | grade |
+--------+------------+-------+
|     20 | RESEARCH   |     4 |
|     30 | SALES      |     3 |
|     10 | ACCOUNTING |     4 |
+--------+------------+-------+

# (2)平均薪水等级最低的部门
select min(f.grade) minGrade 
from (select t.deptno,t.dname,s.grade
        from (select e.deptno,d.dname,avg(sal) avgsal 
                from emp e join dept d on e.deptno=d.deptno
                group by deptno) t
        join salgrade s 
        on t.avgsal between s.losal and s.hisal) f;
+----------+
| minGrade |
+----------+
|        3 |
+----------+

# (3)最低等级的部门名称(用where或having筛选)
select 
    t.deptno,t.dname,s.grade
from 
    (select e.deptno,d.dname,avg(sal) avgsal 
        from emp e 
        join dept d 
        on e.deptno=d.deptno
        group by deptno) t
join 
    salgrade s 
on 
    t.avgsal between s.losal and s.hisal 
having 
    s.grade = (select min(f.grade) minGrade 
                from (select t.deptno,t.dname,s.grade
                        from (select e.deptno,d.dname,avg(sal) avgsal 
                                from emp e join dept d on e.deptno=d.deptno group by deptno) t
                        join salgrade s on t.avgsal between s.losal and s.hisal) f);
+--------+-------+-------+
| deptno | dname | grade |
+--------+-------+-------+
|     30 | SALES |     3 |
+--------+-------+-------+

8 查询比普通员工最高薪水还要高经理人姓名

# 普通员工没有出现在mgr上
# (1)查找mgr
select distinct mgr from emp;
+------+
| mgr  |
+------+
| 7902 |
| 7698 |
| 7839 |
| 7566 |
| NULL |
| 7788 |
| 7782 |
+------+

select * from emp where empno in (select distinct mgr from emp);
+-------+-------+-----------+------+------------+---------+------+--------+
| EMPNO | ENAME | JOB       | MGR  | HIREDATE   | SAL     | COMM | DEPTNO |
+-------+-------+-----------+------+------------+---------+------+--------+
|  7902 | FORD  | ANALYST   | 7566 | 1981-12-03 | 3000.00 | NULL |     20 |
|  7698 | BLAKE | MANAGER   | 7839 | 1981-05-01 | 2850.00 | NULL |     30 |
|  7839 | KING  | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL |     10 |
|  7566 | JONES | MANAGER   | 7839 | 1981-04-02 | 2975.00 | NULL |     20 |
|  7788 | SCOTT | ANALYST   | 7566 | 1987-04-19 | 3000.00 | NULL |     20 |
|  7782 | CLARK | MANAGER   | 7839 | 1981-06-09 | 2450.00 | NULL |     10 |
+-------+-------+-----------+------+------------+---------+------+--------+

# (2)筛选普通员工
select * from emp where empno not in (select distinct mgr from emp);
Empty set (0.00 sec)  #not in 不会自动忽略空值,in会自动忽略空值
select * from emp where empno not in (select distinct mgr from emp where mgr is not null);
+-------+--------+----------+------+------------+---------+---------+--------+
| EMPNO | ENAME  | JOB      | MGR  | HIREDATE   | SAL     | COMM    | DEPTNO |
+-------+--------+----------+------+------------+---------+---------+--------+
|  7369 | SMITH  | CLERK    | 7902 | 1980-12-17 |  800.00 |    NULL |     20 |
|  7499 | ALLEN  | SALESMAN | 7698 | 1981-02-20 | 1600.00 |  300.00 |     30 |
|  7521 | WARD   | SALESMAN | 7698 | 1981-02-22 | 1250.00 |  500.00 |     30 |
|  7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 |     30 |
|  7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 |    0.00 |     30 |
|  7876 | ADAMS  | CLERK    | 7788 | 1987-05-23 | 1100.00 |    NULL |     20 |
|  7900 | JAMES  | CLERK    | 7698 | 1981-12-03 |  950.00 |    NULL |     30 |
|  7934 | MILLER | CLERK    | 7782 | 1982-01-23 | 1300.00 |    NULL |     10 |
+-------+--------+----------+------+------------+---------+---------+--------+

# (3)查找最高薪水
select max(sal) as maxsal from emp where empno not in (select distinct mgr from emp where mgr is not null);
+---------+
| maxsal  |
+---------+
| 1600.00 |
+---------+

# (4)比普通员工最高薪水的经理人名字
select ename,sal from emp
where sal>(select max(sal) as maxsal from emp 
            where empno not in (select distinct mgr from emp where mgr is not null));
+-------+---------+
| ename | sal     |
+-------+---------+
| JONES | 2975.00 |
| BLAKE | 2850.00 |
| CLARK | 2450.00 |
| SCOTT | 3000.00 |
| KING  | 5000.00 |
| FORD  | 3000.00 |
+-------+---------+

9 查询薪水最高的前五名员工

select ename,sal from emp 
order by sal desc
limit 5;
+-------+---------+
| ename | sal     |
+-------+---------+
| KING  | 5000.00 |
| SCOTT | 3000.00 |
| FORD  | 3000.00 |
| JONES | 2975.00 |
| BLAKE | 2850.00 |
+-------+---------+

10 查询薪水最高的第6-10名员工

select ename,sal from emp
order by sal desc
limit 5,5;
+--------+---------+
| ename  | sal     |
+--------+---------+
| CLARK  | 2450.00 |
| ALLEN  | 1600.00 |
| TURNER | 1500.00 |
| MILLER | 1300.00 |
| WARD   | 1250.00 |
+--------+---------+

11 查询最后入职的5名员工

select ename,hiredate from emp
order by hiredate
limit 5;
+-------+------------+
| ename | hiredate   |
+-------+------------+
| SMITH | 1980-12-17 |
| ALLEN | 1981-02-20 |
| WARD  | 1981-02-22 |
| JONES | 1981-04-02 |
| BLAKE | 1981-05-01 |
+-------+------------+

12 查询每个薪水等级多少员工

# (1)每个员工的薪水等级
select e.ename,s.grade,e.sal from emp e
join salgrade s
on e.sal between s.losal and s.hisal;
+--------+-------+---------+
| ename  | grade | sal     |
+--------+-------+---------+
| SMITH  |     1 |  800.00 |
| ALLEN  |     3 | 1600.00 |
| WARD   |     2 | 1250.00 |
| JONES  |     4 | 2975.00 |
| MARTIN |     2 | 1250.00 |
| BLAKE  |     4 | 2850.00 |
| CLARK  |     4 | 2450.00 |
| SCOTT  |     4 | 3000.00 |
| KING   |     5 | 5000.00 |
| TURNER |     3 | 1500.00 |
| ADAMS  |     1 | 1100.00 |
| JAMES  |     1 |  950.00 |
| FORD   |     4 | 3000.00 |
| MILLER |     2 | 1300.00 |
+--------+-------+---------+

# (2)临时表t,分组函数group by
select t.grade,count(t.grade) courtgrade
from (select e.ename,s.grade,e.sal from emp e 
        join salgrade s on e.sal between s.losal and s.hisal) t
group by t.grade;
+-------+------------+
| grade | courtgrade |
+-------+------------+
|     1 |          3 |
|     3 |          2 |
|     2 |          3 |
|     4 |          5 |
|     5 |          1 |
+-------+------------+

13 列出所有员工及领导名字

# 一张表当作两张表,所有员工需要left join
select e.ename,b.ename as leadername
from emp e 
left join emp b
on e.mgr=b.empno;
+--------+------------+
| ename  | leadername |
+--------+------------+
| SMITH  | FORD       |
| ALLEN  | BLAKE      |
| WARD   | BLAKE      |
| JONES  | KING       |
| MARTIN | BLAKE      |
| BLAKE  | KING       |
| CLARK  | KING       |
| SCOTT  | JONES      |
| KING   | NULL       |
| TURNER | BLAKE      |
| ADAMS  | SCOTT      |
| JAMES  | BLAKE      |
| FORD   | JONES      |
| MILLER | CLARK      |
+--------+------------+

14 受雇日期早于其直接上级所有员工编号、姓名、部门名称

# (1)所有员工、领导的编号、姓名
select e.empno,e.deptno,e.ename,e.hiredate,b.ename as leadername,b.hiredate as leaderhiredate
from emp e
left join emp b
on e.mgr=b.empno;
+-------+--------+--------+------------+------------+----------------+
| empno | deptno | ename  | hiredate   | leadername | leaderhiredate |
+-------+--------+--------+------------+------------+----------------+
|  7369 |     20 | SMITH  | 1980-12-17 | FORD       | 1981-12-03     |
|  7499 |     30 | ALLEN  | 1981-02-20 | BLAKE      | 1981-05-01     |
|  7521 |     30 | WARD   | 1981-02-22 | BLAKE      | 1981-05-01     |
|  7566 |     20 | JONES  | 1981-04-02 | KING       | 1981-11-17     |
|  7654 |     30 | MARTIN | 1981-09-28 | BLAKE      | 1981-05-01     |
|  7698 |     30 | BLAKE  | 1981-05-01 | KING       | 1981-11-17     |
|  7782 |     10 | CLARK  | 1981-06-09 | KING       | 1981-11-17     |
|  7788 |     20 | SCOTT  | 1987-04-19 | JONES      | 1981-04-02     |
|  7839 |     10 | KING   | 1981-11-17 | NULL       | NULL           |
|  7844 |     30 | TURNER | 1981-09-08 | BLAKE      | 1981-05-01     |
|  7876 |     20 | ADAMS  | 1987-05-23 | SCOTT      | 1987-04-19     |
|  7900 |     30 | JAMES  | 1981-12-03 | BLAKE      | 1981-05-01     |
|  7902 |     20 | FORD   | 1981-12-03 | JONES      | 1981-04-02     |
|  7934 |     10 | MILLER | 1982-01-23 | CLARK      | 1981-06-09     |
+-------+--------+--------+------------+------------+----------------+

# (2)早于上级的所有员工的编号、姓名
select t.deptno,t.ename
from (select e.deptno,e.ename,e.hiredate,b.ename as leadername,b.hiredate as leaderhiredate
        from emp e left join emp b on e.mgr=b.empno) t
where t.hiredate<t.leaderhiredate;
+--------+-------+
| deptno | ename |
+--------+-------+
|     20 | SMITH |
|     30 | ALLEN |
|     30 | WARD  |
|     20 | JONES |
|     30 | BLAKE |
|     10 | CLARK |
+--------+-------+

# (3)早于上级的所有员工的编号、姓名、部门名称
select f.empno,f.ename,d.dname
from (select t.empno,t.deptno,t.ename
        from (select e.empno,e.deptno,e.ename,e.hiredate,b.ename leadername,b.hiredate 
               leaderhiredate
                from emp e left join emp b on e.mgr=b.empno) t
        where t.hiredate<t.leaderhiredate) f
join dept d
on d.deptno=f.deptno;
+-------+-------+------------+
| empno | ename | dname      |
+-------+-------+------------+
|  7369 | SMITH | RESEARCH   |
|  7499 | ALLEN | SALES      |
|  7521 | WARD  | SALES      |
|  7566 | JONES | RESEARCH   |
|  7698 | BLAKE | SALES      |
|  7782 | CLARK | ACCOUNTING |
+-------+-------+------------+
# 化简版
select d.dname,e.empno,e.ename
from emp e
join emp b
on e.mgr=b.empno
join dept d
on e.deptno=d.deptno
where e.hiredate>b.hiredate;
+------------+-------+--------+
| dname      | empno | ename  |
+------------+-------+--------+
| SALES      |  7654 | MARTIN |
| RESEARCH   |  7788 | SCOTT  |
| SALES      |  7844 | TURNER |
| RESEARCH   |  7876 | ADAMS  |
| SALES      |  7900 | JAMES  |
| RESEARCH   |  7902 | FORD   |
| ACCOUNTING |  7934 | MILLER |
+------------+-------+--------+

15 列出部门名称和员工信息,同时列出没有员工的部门

select d.dname,e.*
from emp e
right join dept d
on e.deptno=d.deptno;
+------------+-------+--------+-----------+------+------------+---------+---------+--------+
| dname      | EMPNO | ENAME  | JOB       | MGR  | HIREDATE   | SAL     | COMM    | DEPTNO |
+------------+-------+--------+-----------+------+------------+---------+---------+--------+
| ACCOUNTING |  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 |    NULL |     10 |
| ACCOUNTING |  7839 | KING   | PRESIDENT | NULL | 1981-11-17 | 5000.00 |    NULL |     10 |
| ACCOUNTING |  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 |    NULL |     10 |
| RESEARCH   |  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 |    NULL |     20 |
| RESEARCH   |  7876 | ADAMS  | CLERK     | 7788 | 1987-05-23 | 1100.00 |    NULL |     20 |
| RESEARCH   |  7788 | SCOTT  | ANALYST   | 7566 | 1987-04-19 | 3000.00 |    NULL |     20 |
| RESEARCH   |  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975.00 |    NULL |     20 |
| RESEARCH   |  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800.00 |    NULL |     20 |
| SALES      |  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950.00 |    NULL |     30 |
| SALES      |  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 |    0.00 |     30 |
| SALES      |  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850.00 |    NULL |     30 |
| SALES      |  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 1400.00 |     30 |
| SALES      |  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 |  500.00 |     30 |
| SALES      |  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 |  300.00 |     30 |
| OPERATIONS |  NULL | NULL   | NULL      | NULL | NULL       |    NULL |    NULL |   NULL |
+------------+-------+--------+-----------+------+------------+---------+---------+--------+

16 列出至少5个员工所有部门

# (1)每个部门的员工数量
select e.deptno,count(e.ename) as totalEmp
from emp e
group by e.deptno;
+--------+----------+
| deptno | totalEmp |
+--------+----------+
|     20 |        5 |
|     30 |        6 |
|     10 |        3 |
+--------+----------+

# (2)有5个员工的部门
select t.deptno,t.totalEmp
from (select e.deptno,count(e.ename) as totalEmp
        from emp e group by e.deptno) t
where t.totalEmp>=5;
+--------+----------+
| deptno | totalEmp |
+--------+----------+
|     20 |        5 |
|     30 |        6 |
+--------+----------+

select e.deptno,count(e.ename) as totalEmp
from emp e
group by e.deptno
having totalEmp>=5;
+--------+----------+
| deptno | totalEmp |
+--------+----------+
|     20 |        5 |
|     30 |        6 |
+--------+----------+

17 列出薪水“SMITH”多的所有员工信息

# (1)查询"SMITH"薪水
select sal from emp where ename="SMITH";
+--------+
| sal    |
+--------+
| 800.00 |
+--------+

# (2)比较
select * from emp where sal>(select sal from emp where ename="SMITH");
+-------+--------+-----------+------+------------+---------+---------+--------+
| EMPNO | ENAME  | JOB       | MGR  | HIREDATE   | SAL     | COMM    | DEPTNO |
+-------+--------+-----------+------+------------+---------+---------+--------+
|  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 |  300.00 |     30 |
|  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 |  500.00 |     30 |
|  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975.00 |    NULL |     20 |
|  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 1400.00 |     30 |
|  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850.00 |    NULL |     30 |
|  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 |    NULL |     10 |
|  7788 | SCOTT  | ANALYST   | 7566 | 1987-04-19 | 3000.00 |    NULL |     20 |
|  7839 | KING   | PRESIDENT | NULL | 1981-11-17 | 5000.00 |    NULL |     10 |
|  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 |    0.00 |     30 |
|  7876 | ADAMS  | CLERK     | 7788 | 1987-05-23 | 1100.00 |    NULL |     20 |
|  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950.00 |    NULL |     30 |
|  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 |    NULL |     20 |
|  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 |    NULL |     10 |
+-------+--------+-----------+------+------------+---------+---------+--------+

 ——数据:bjpowernode.sql

DROP TABLE IF EXISTS EMP;
DROP TABLE IF EXISTS DEPT;
DROP TABLE IF EXISTS SALGRADE;

CREATE TABLE DEPT
       (DEPTNO int(2) not null ,
	DNAME VARCHAR(14) ,
	LOC VARCHAR(13),
	primary key (DEPTNO)
	);
CREATE TABLE EMP
       (EMPNO int(4)  not null ,
	ENAME VARCHAR(10),
	JOB VARCHAR(9),
	MGR INT(4),
	HIREDATE DATE  DEFAULT NULL,
	SAL DOUBLE(7,2),
	COMM DOUBLE(7,2),
	primary key (EMPNO),
	DEPTNO INT(2) 
	)
	;

CREATE TABLE SALGRADE
      ( GRADE INT,
	LOSAL INT,
	HISAL INT );

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'); 
commit;
 
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); 
commit;
 
INSERT INTO SALGRADE ( GRADE, LOSAL, HISAL ) VALUES ( 1, 700, 1200); 
INSERT INTO SALGRADE ( GRADE, LOSAL, HISAL ) VALUES ( 2, 1201, 1400); 
INSERT INTO SALGRADE ( GRADE, LOSAL, HISAL ) VALUES ( 3, 1401, 2000); 
INSERT INTO SALGRADE ( GRADE, LOSAL, HISAL ) VALUES ( 4, 2001, 3000); 
INSERT INTO SALGRADE ( GRADE, LOSAL, HISAL ) VALUES ( 5, 3001, 9999); 
commit;
dept
+--------+------------+----------+
| DEPTNO | DNAME      | LOC      |
+--------+------------+----------+
|     10 | ACCOUNTING | NEW YORK |
|     20 | RESEARCH   | DALLAS   |
|     30 | SALES      | CHICAGO  |
|     40 | OPERATIONS | BOSTON   |
+--------+------------+----------+

emp
+-------+--------+-----------+------+------------+---------+---------+--------+
| EMPNO | ENAME  | JOB       | MGR  | HIREDATE   | SAL     | COMM    | DEPTNO |
+-------+--------+-----------+------+------------+---------+---------+--------+
|  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800.00 |    NULL |     20 |
|  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 |  300.00 |     30 |
|  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 |  500.00 |     30 |
|  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975.00 |    NULL |     20 |
|  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 1400.00 |     30 |
|  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850.00 |    NULL |     30 |
|  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 |    NULL |     10 |
|  7788 | SCOTT  | ANALYST   | 7566 | 1987-04-19 | 3000.00 |    NULL |     20 |
|  7839 | KING   | PRESIDENT | NULL | 1981-11-17 | 5000.00 |    NULL |     10 |
|  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 |    0.00 |     30 |
|  7876 | ADAMS  | CLERK     | 7788 | 1987-05-23 | 1100.00 |    NULL |     20 |
|  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950.00 |    NULL |     30 |
|  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 |    NULL |     20 |
|  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 |    NULL |     10 |
+-------+--------+-----------+------+------------+---------+---------+--------+

salgrade
+-------+-------+-------+
| GRADE | LOSAL | HISAL |
+-------+-------+-------+
|     1 |   700 |  1200 |
|     2 |  1201 |  1400 |
|     3 |  1401 |  2000 |
|     4 |  2001 |  3000 |
|     5 |  3001 |  9999 |
+-------+-------+-------+

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/433135.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如何使用 GPT-4 为博客目录页打造炫酷前端效果

前不久我用 cmd markdown 写了篇文章《项目 TO 的自我修养》&#xff0c;文章的目录如下&#xff1a; 当我把它发布到线上后&#xff0c;目录却只展示出了二级标题&#xff1a; 这哪行&#xff01;我猜这个可能就是加个配置啥的就能修复。于是马上就问 GPT-4 怎么办&#xff1f…

25.SSM-SpringMVC延续--拦截器与异常处理思想

目录 一、拦截器。 &#xff08;1&#xff09;拦截器的作用。 &#xff08;2&#xff09;拦截器与过滤器的区别。 &#xff08;3&#xff09;拦截器的方法。 &#xff08;4&#xff09;拦截器的快速入门。 &#xff08;5&#xff09;多拦截器。 &#xff08;5.1&#xf…

哈工大软件构造-设计模式笔记

文章目录 UML简单知识1&#xff0e;单例模式2.工厂方法模式3&#xff0e;迭代器模式4&#xff0e;策略模式5&#xff0e;建造者模式6&#xff0e;模板方法模式7&#xff0e;代理模式8&#xff0e;责任链模式9&#xff0e;抽象工厂模式10&#xff0e;适配器模式11&#xff0e;观…

计算机操作系统复习记录(总结 —— 快速入门和快速复习)

1. 操作系统 概念&#xff1a;是控制和管理整个计算机系统的硬件和软件资源&#xff0c;并合理地组织调度计算机的工作和资源的分配&#xff0c;以提供给用户和其它软件接口和环境&#xff0c;它是计算机系统中最基本的系统软件。 功能和目标&#xff1a; &#xff08;1&…

数据库同步 Elasticsearch 后数据不一致,怎么办?

1、实战线上问题 Q1&#xff1a;Logstash 同步 postgreSQL 到 Elasticsearch 数据不一致。 在使用 Logstash 从 pg 库中将一张表导入到 ES 中时&#xff0c;发现 ES 中的数据量和 PG 库中的这张表的数据量存在较大差距。如何快速比对哪些数据没有插入&#xff1f;导入过程中&am…

六:内存回收

内存回收&#xff1a; 应用程序通过 malloc 函数申请内存的时候&#xff0c;实际上申请的是虚拟内存&#xff0c;此时并不会分配物理内存。 当应用程序读写了这块虚拟内存&#xff0c;CPU 就会去访问这个虚拟内存&#xff0c; 这时会发现这个虚拟内存没有映射到物理内存&…

系统安全及应用

目录 一、账号安全控制 1&#xff09;系统账号清理 2&#xff09;密码安全控制 chage命令 示例 3&#xff09;命令历史限制 4&#xff09;终端自动注销 总结 账号安全 密码安全 二、系统引导和登录控制 1&#xff09;使用su命令切换用户 用途及用…

【学习笔记】字节数据和字节字符串(b“ “)那些事

文章目录 0 前言1 先来看看C语言中怎么处理这种字节数据1.1 使用总结 2 再来看看Python当中是怎么处理字节数据的 0 前言 最近在尝试用PyQt做一个上位机&#xff0c;遇到很多关于字节字符串的问题&#xff0c;这里简单总结几个关键点。 1 先来看看C语言中怎么处理这种字节数据…

RK3568平台开发系列讲解(Linux系统篇)共享内存的创建和映射过程

🚀返回专栏总目录 文章目录 一、共享内存的创建和映射过程流程梳理二、如何创建共享内存?三、如何将共享内存映射到虚拟地址空间?沉淀、分享、成长,让自己和他人都能有所收获!😄 📢本篇我们一起学习下共享内存的创建和映射过程。 一、共享内存的创建和映射过程流程梳…

推荐5款重度电脑用户也未必知道的小众软件

作为一个重度电脑用户&#xff0c;你可能会经常使用一些软件来完成各种任务和娱乐。但是你知道有哪些好用的WIN10软件吗&#xff1f;今天我就为你介绍一下我推荐的五款WIN10软件&#xff0c;它们分别是&#xff1a; 1.反恶意软件——Malwarebytes Malwarebytes是一款专业的反…

AOP与SpringBoot使用AOP实例

AOP&#xff1a;Aspect Oriented Programming&#xff08;面向切面编程、面向方面编程&#xff09;&#xff0c;其实就是面向特定方法编程。 动态代理是面向切面编程最主流的实现。而SpringAOP是Spring框架的高级技术&#xff0c;旨在管理bean对象的过程中&#xff0c;主要通过…

浅谈thrift协议+举例通用mockserver如何实现

目录 简单来说&#xff1a; 举个例子&#xff1a; 简单来说&#xff1a; 1&#xff09;是一个跨平台跨语言的通信协议&#xff0c;定义和创建跨语言服务&#xff0c;是一个高性能、轻量级RPC框架。 2&#xff09;开发者无需关注不同语言/相同语言服务间如何通信&#xff0c;…

基于html+css的图片展示15

准备项目 项目开发工具 Visual Studio Code 1.44.2 版本: 1.44.2 提交: ff915844119ce9485abfe8aa9076ec76b5300ddd 日期: 2020-04-16T16:36:23.138Z Electron: 7.1.11 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT x64 10.0.19044 项目…

什么是Python?

目录 Python简介 Python发展史 Python优点与缺点 Python现如今的应用领域 总结 Python简介 Python是一种高级、解释型、面向对象的动态编程语言&#xff0c;由Guido van Rossum在1989年创建&#xff0c;首次发布于1991年。 Python设计的哲学是优雅、清晰、简单&#xff0c…

Windows逆向安全(一)之基础知识(八)

if else嵌套 这次来研究if else嵌套在汇编中的表现形式&#xff0c;本次以获取三个数中最大的数这个函数为例子&#xff0c;分析if else的汇编形式 求三个数中的最大值 首先贴上代码&#xff1a; #include "stdafx.h"int result0; int getMax(int i,int j,int k)…

机器视觉工程师必须知道机器视觉精度要思考哪些

​在和客户交流项目技术要求,这个项目,我要求的精度是0.01mm? 第一个问题:什么是精度? 精度要求0.01mm: 1.视觉重复性极差?静态?动态? 2.视觉与第三方相关性差异?极差?相关性系数? 3.整体系统误差?机械重复性误差? 4.产品尺寸公差? 第二个问题:精度与公差…

完美解决丨TypeError: fun() takes 2 positional arguments but 3 were given

python def fun(a, b): return a b c fun(1, 2, 3) Traceback (most recent call last): File "test.py", line 5, in <module c fun(1, 2, 3) TypeError: fun() takes 2 positional arguments but 3 were given 上面的代码中&#xff0c; fun 函数定义了两…

最通俗的语言解释01背包问题(力扣416题javascript版本)

【声明】以下内容参考了代码随想录&#xff0c;不用作商业用途~ 先来看一个场景&#xff1a;有N件物品&#xff0c;背包最大的重量为W&#xff0c;第i件物品的重量为weight[i]&#xff0c;得到的价值为value[i]&#xff0c;每件物品只用一次&#xff08;即不能重复放进背包&…

【计算方法】正交区域查询---KD-Tree概念

一、说明 kd 树是一种二叉树数据结构&#xff0c;可以用来进行高效的 kNN 计算。kd 树算法偏于复杂&#xff0c;本篇将先介绍以二叉树的形式来记录和索引空间的思路&#xff0c;以便读者更轻松地理解 kd 树。 二、正交区域查找 2.1 定义 对于k维空间的张量数据表格&#xff0…

Unity RenderStreaming 云渲染3.1.0-exp.6 食用手册

Unity云渲染 &#x1f957;资源&#x1f364;兼容性&#x1f367;手机端连接&#x1f969;安装方法&#x1f35b;IP端口设置&#x1f371;官方案例尝鲜&#x1f332;导入案例&#x1f332;添加场景&#x1f332;启动WebApp&#x1f332;打开Menu场景&#x1f332;连接参数设置&…