Add emp-dept exercises.
This commit is contained in:
parent
3f2a424292
commit
4c13a8fb9d
56
1/GBD/assignments/ej-emp-dept.sql
Normal file
56
1/GBD/assignments/ej-emp-dept.sql
Normal file
@ -0,0 +1,56 @@
|
||||
-- 1
|
||||
SELECT ename FROM emp WHERE sal > (SELECT sal FROM emp WHERE ename = 'JAMES');
|
||||
|
||||
-- 2
|
||||
SELECT ename FROM emp WHERE deptno = (SELECT deptno FROM emp WHERE ename='SMITH');
|
||||
|
||||
-- 3
|
||||
SELECT ROUND(AVG(sal), 2) FROM emp WHERE deptno = (SELECT deptno FROM emp WHERE ename='JAMES');
|
||||
|
||||
-- 4
|
||||
SELECT ename FROM emp WHERE hiredate < (SELECT hiredate FROM emp WHERE ename='MILLER');
|
||||
|
||||
-- 5
|
||||
SELECT ename FROM emp WHERE deptno = (SELECT deptno FROM emp WHERE ename='FORD') AND
|
||||
sal > (SELECT sal FROM emp WHERE ename='JAMES');
|
||||
|
||||
-- 6
|
||||
SELECT dept.dname FROM emp JOIN dept ON emp.deptno = dept.deptno WHERE ename='SCOTT';
|
||||
|
||||
-- 7
|
||||
SELECT COUNT(*) FROM emp WHERE sal < (SELECT sal FROM emp WHERE ename='MILLER');
|
||||
|
||||
-- 8
|
||||
SELECT dept.loc FROM emp JOIN dept ON emp.deptno = dept.deptno WHERE emp.ename='KING';
|
||||
|
||||
-- 9
|
||||
SELECT DISTINCT dept.dname FROM emp JOIN dept ON emp.deptno = dept.deptno WHERE emp.job='CLERK';
|
||||
|
||||
-- 10
|
||||
SELECT DISTINCT dname FROM dept WHERE deptno NOT IN (SELECT deptno FROM emp WHERE job = 'ANALYST');
|
||||
|
||||
-- 11
|
||||
SELECT ename FROM emp JOIN dept ON emp.deptno = dept.deptno WHERE dept.loc = 'DALLAS' ORDER BY ename;
|
||||
|
||||
-- 12
|
||||
SELECT ename, sal FROM emp WHERE job = (SELECT job FROM emp WHERE ename='JONES') AND ename != 'JONES';
|
||||
|
||||
-- 13
|
||||
SELECT * FROM emp
|
||||
WHERE deptno = (SELECT deptno FROM emp WHERE ename='SCOTT') AND
|
||||
sal > (SELECT sal FROM emp WHERE ename='SMITH') AND
|
||||
job = (SELECT job FROM emp WHERE ename='MILLER');
|
||||
|
||||
-- 14
|
||||
SELECT * FROM emp
|
||||
WHERE deptno = (SELECT deptno FROM emp WHERE ename='MARTIN') AND
|
||||
sal = (SELECT sal FROM emp WHERE ename='MARTIN');
|
||||
|
||||
-- 15
|
||||
SELECT ename, sal FROM emp
|
||||
WHERE deptno = (SELECT deptno FROM emp WHERE ename='FORD') AND
|
||||
sal = (SELECT sal FROM emp WHERE ename='FORD')
|
||||
ORDER BY ename ASC, sal DESC;
|
||||
|
||||
-- 16
|
||||
SELECT MAX(sal) FROM emp GROUP BY deptno HAVING deptno IN (10, 20);
|
Loading…
Reference in New Issue
Block a user