Add more to emp-dept exercise.
This commit is contained in:
parent
7e13ff581c
commit
a5ae238d89
@ -53,4 +53,39 @@ SELECT ename, sal FROM emp
|
|||||||
ORDER BY ename ASC, sal DESC;
|
ORDER BY ename ASC, sal DESC;
|
||||||
|
|
||||||
-- 16
|
-- 16
|
||||||
SELECT MAX(sal) FROM emp GROUP BY deptno HAVING deptno IN (10, 20);
|
SELECT (SELECT MAX(sal) FROM emp WHERE deptno=10) "deptno 10",
|
||||||
|
(SELECT MAX(sal) FROM emp WHERE deptno=20) "deptno 20" FROM dual;
|
||||||
|
|
||||||
|
-- 17
|
||||||
|
SELECT (SELECT MIN(sal) FROM emp WHERE deptno=10) "min sal depnto 10",
|
||||||
|
(SELECT COUNT(*) FROM emp WHERE deptno=20) "employees deptno 20",
|
||||||
|
(SELECT AVG(sal) FROM emp WHERE deptno=30) "avg sal deptno 30" FROM dual;
|
||||||
|
|
||||||
|
-- 18
|
||||||
|
SELECT ename "NOMBRE", sal+NVL(comm, 0) "SALARIO_TOTAL"
|
||||||
|
FROM emp
|
||||||
|
WHERE deptno=20 ORDER BY ename;
|
||||||
|
|
||||||
|
-- 19
|
||||||
|
SELECT ename "NOMBRE", sal+NVL(comm, 0) "SALARIO_TOTAL" FROM emp
|
||||||
|
WHERE deptno=10 AND sal > 2000
|
||||||
|
UNION
|
||||||
|
SELECT ename, sal+NVL(comm, 0) FROM emp
|
||||||
|
WHERE sal > 1200
|
||||||
|
ORDER BY SALARIO_TOTAL DESC;
|
||||||
|
|
||||||
|
-- 20
|
||||||
|
SELECT deptno, ename FROM emp
|
||||||
|
WHERE deptno IN (SELECT deptno FROM emp WHERE ename IN ('JAMES', 'SCOTT')) AND
|
||||||
|
ename NOT IN ('JAMES', 'SCOTT')
|
||||||
|
ORDER BY deptno, ename;
|
||||||
|
|
||||||
|
-- 21
|
||||||
|
SELECT dname FROM emp JOIN dept ON emp.deptno=dept.deptno GROUP BY dept.dname HAVING COUNT(*) > 4;
|
||||||
|
|
||||||
|
-- 23
|
||||||
|
SELECT deptno, ROUND(AVG(sal), 2) FROM emp
|
||||||
|
WHERE deptno IN (SELECT DISTINCT deptno FROM emp WHERE job='SALESMAN') GROUP BY deptno;
|
||||||
|
|
||||||
|
-- 24
|
||||||
|
SELECT deptno, COUNT(*) "NUM" FROM emp GROUP BY deptno ORDER BY NUM DESC LIMIT 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user