Ejercicios de SQL (5) (2020-04-12)

En vista de mi escasa capacidad para escribir sentencias SQL, a menudo haré algunos ejercicios de sentencias SQL en el futuro. Primero, fíjese una pequeña meta: primero haga todos los ejercicios de SQL que pueda encontrar en Internet.

————————————————————————————————————————————————— ————

Aquí hay algunas tablas que vienen con Oracle, bajo el usuario de Scott.

Vea cómo liberar a los usuarios de scott: https://blog.csdn.net/qq_26896085/article/details/105342212

--查询员工编号,员工姓名,经理的编号,经理的姓名
select e1.empno, e1.ename, e2.empno, e2.ename from emp e1, emp e2 where e1.mgr = e2.empno;
--查询员工编号,员工姓名,员工的部门名称,经理的编号,经理的姓名
select e1.empno, e1.ename, dname, e2.empno, e2.ename from emp e1, emp e2, dept where e1.mgr = e2.empno and e1.deptno = dept.deptno order by dname;
--查询员工编号,员工姓名,员工的部门名称,员工的工资等级,经理的编号,经理的姓名,经理的部门名称
select e1.empno, e1.ename, d1.dname, salgrade.grade, e1.mgr, e2.ename, d2.dname from emp e1, emp e2, dept d1, dept d2, salgrade 
where e1.mgr = e2.empno and e1.deptno = d1.deptno and e2.deptno = d2.deptno and e1.sal between salgrade.losal and salgrade.hisal;
--查询员工编号,员工姓名,员工的部门名称,员工的工资等级,经理的编号,经理的姓名,经理的部门名称,经理的工资等级
select e1.empno, e1.ename, d1.dname, s1.grade, e1.mgr, e2.ename, d2.dname, s2.grade from emp e1, emp e2, dept d1, dept d2, salgrade s1, salgrade s2
where e1.mgr = e2.empno and e1.deptno = d1.deptno and e2.deptno = d2.deptno and e1.sal between s1.losal and s1.hisal and e2.sal between s2.losal and s2.hisal;
--查询员工编号,员工姓名,员工的部门名称,员工的工资等级,经理的编号,经理的姓名,经理的 部门名称,经理的工资等级 --将工资等级 1,2,3,4 显示成 one, two, three, four, five
select e1.empno, e1.ename, d1.dname, 
       decode(s1.grade, 1, 'one', 2, 'tow', 3, 'three', 4, 'four', 'five') "grade1",
       e1.mgr, e2.ename, d2.dname, s2.grade,
       decode(s2.grade, 1, 'one', 2, 'tow', 3, 'three', 4, 'four', 'five') "grade2"
from emp e1, emp e2, dept d1, dept d2, salgrade s1, salgrade s2
where e1.mgr = e2.empno and e1.deptno = d1.deptno and e2.deptno = d2.deptno and e1.sal between s1.losal and s1.hisal and e2.sal between s2.losal and s2.hisal;
--
select e1.empno, e1.ename, d1.dname, 
       case s1.grade
         when 1 then 'one'
         when 2 then 'two'
         when 3 then 'three'
         when 4 then 'four'
         when 5 then 'five'
       end "grade1",
       e1.mgr, e2.ename, d2.dname, s2.grade,
       case s2.grade
         when 1 then 'one'
         when 2 then 'two'
         when 3 then 'three'
         when 4 then 'four'
         when 5 then 'five'
       end "grade1"
from emp e1, emp e2, dept d1, dept d2, salgrade s1, salgrade s2
where e1.mgr = e2.empno and e1.deptno = d1.deptno and e2.deptno = d2.deptno and e1.sal between s1.losal and s1.hisal and e2.sal between s2.losal and s2.hisal;
--查询员工姓名和员工部门所处的位置
select ename, loc from emp, dept where emp.deptno = dept.deptno;
select ename, loc from emp join dept on emp.deptno = dept.deptno;

 

Supongo que te gusta

Origin blog.csdn.net/qq_26896085/article/details/105479741
Recomendado
Clasificación