Finished exercises emp_dept
This commit is contained in:
parent
a5ae238d89
commit
b7601dd6d8
@ -57,7 +57,7 @@ SELECT (SELECT MAX(sal) FROM emp WHERE deptno=10) "deptno 10",
|
|||||||
(SELECT MAX(sal) FROM emp WHERE deptno=20) "deptno 20" FROM dual;
|
(SELECT MAX(sal) FROM emp WHERE deptno=20) "deptno 20" FROM dual;
|
||||||
|
|
||||||
-- 17
|
-- 17
|
||||||
SELECT (SELECT MIN(sal) FROM emp WHERE deptno=10) "min sal depnto 10",
|
SELECT (SELECT MIN(sal) FROM emp WHERE deptno=10) "min sal deptno 10",
|
||||||
(SELECT COUNT(*) FROM emp WHERE deptno=20) "employees deptno 20",
|
(SELECT COUNT(*) FROM emp WHERE deptno=20) "employees deptno 20",
|
||||||
(SELECT AVG(sal) FROM emp WHERE deptno=30) "avg sal deptno 30" FROM dual;
|
(SELECT AVG(sal) FROM emp WHERE deptno=30) "avg sal deptno 30" FROM dual;
|
||||||
|
|
||||||
@ -88,4 +88,48 @@ SELECT deptno, ROUND(AVG(sal), 2) FROM emp
|
|||||||
WHERE deptno IN (SELECT DISTINCT deptno FROM emp WHERE job='SALESMAN') GROUP BY deptno;
|
WHERE deptno IN (SELECT DISTINCT deptno FROM emp WHERE job='SALESMAN') GROUP BY deptno;
|
||||||
|
|
||||||
-- 24
|
-- 24
|
||||||
SELECT deptno, COUNT(*) "NUM" FROM emp GROUP BY deptno ORDER BY NUM DESC LIMIT 1;
|
SELECT deptno FROM emp
|
||||||
|
GROUP BY deptno HAVING COUNT(*) =
|
||||||
|
(SELECT MAX(COUNT(*)) FROM emp
|
||||||
|
GROUP BY deptno);
|
||||||
|
|
||||||
|
-- 25
|
||||||
|
SELECT dname FROM dept
|
||||||
|
WHERE deptno=(
|
||||||
|
SELECT deptno FROM emp
|
||||||
|
GROUP BY deptno HAVING COUNT(*) =
|
||||||
|
(SELECT MAX(COUNT(*)) FROM emp
|
||||||
|
GROUP BY deptno));
|
||||||
|
|
||||||
|
-- 26
|
||||||
|
SELECT ename, sal FROM emp
|
||||||
|
WHERE deptno=(
|
||||||
|
SELECT deptno FROM emp
|
||||||
|
GROUP BY deptno HAVING COUNT(*) =
|
||||||
|
(SELECT MAX(COUNT(*)) FROM emp
|
||||||
|
GROUP BY deptno)) ORDER BY ename;
|
||||||
|
|
||||||
|
-- 27
|
||||||
|
SELECT ROUND(AVG(sal), 2) FROM emp
|
||||||
|
GROUP BY deptno HAVING deptno !=
|
||||||
|
(SELECT deptno FROM emp WHERE ename='SCOTT');
|
||||||
|
|
||||||
|
-- 28
|
||||||
|
SELECT ename FROM emp
|
||||||
|
WHERE mgr IN (
|
||||||
|
SELECT empno FROM emp
|
||||||
|
WHERE sal > (SELECT sal FROM emp WHERE hiredate='1981-04-02'));
|
||||||
|
|
||||||
|
-- 29
|
||||||
|
SELECT job, ename, sal FROM emp
|
||||||
|
WHERE sal > (
|
||||||
|
SELECT AVG(sal) FROM emp WHERE deptno=(
|
||||||
|
SELECT deptno FROM emp WHERE ename='MILLER'));
|
||||||
|
|
||||||
|
-- 30
|
||||||
|
SELECT ename, hiredate FROM emp
|
||||||
|
WHERE hiredate BETWEEN
|
||||||
|
(SELECT hiredate FROM emp WHERE ename='JONES')
|
||||||
|
AND
|
||||||
|
(SELECT hiredate FROM emp WHERE ename='SCOTT')
|
||||||
|
ORDER BY ename;
|
||||||
|
Loading…
Reference in New Issue
Block a user