Professional Documents
Culture Documents
Omar 11
Omar 11
Part 1 : SUBQUERIES
SELECT dname
FROM dept
WHERE deptno IN (
SELECT deptno
FROM emp
GROUP BY deptno
HAVING COUNT(*) > 6
);
DNAME
Sales
2. Display the employees whose location which has at least one o in it.
SELECT *
FROM emp
WHERE LOWER (loc) LIKE '%o%';
3. Select the department name and location of all employees working for Clark
SELECT dname, loc
FROM dept
WHERE deptno = (
SELECT deptno
FROM emp
WHERE ename = 'Clark'
);
4. Display empno,job and salary of all the Analyst who are earning more than any of
the manager
SECONDHIGHESTSALARY
4000
6. Display all the employees in 'Operations and Accounting' Dept. list the employees
who has salary greater than Miller
SELECT *
FROM emp
WHERE deptno IN (
SELECT deptno
FROM dept
WHERE deptno IN ('Operations', 'Accounting')
) AND sal > (
SELECT sal
FROM emp
WHERE ename = 'Miller'
);
7. List employees who work for SALES department and their salary greater than
average salary of their department.
SELECT *
FROM emp
WHERE deptno = (
SELECT deptno
FROM dept
WHERE dname = 'SALES'
) AND sal > (
SELECT AVG(sal)
FROM emp
WHERE deptno = (
SELECT deptno
FROM dept
WHERE dname = 'SALES'
)
);
DEPTNO
30
20
10
Q2: Display the employee name, salary and department no for all the employees who
earn more than 3000 and who work in a department with name contains the character
C. (Use set operators).
SELECT ename, salary, deptno
FROM emp
WHERE sal > 3000
INTERSECT
SELECT ename, sal, deptno
FROM emp
WHERE deptno IN (
SELECT deptno
FROM dept
WHERE LOWER(dname) LIKE '%c%'
);
Q3: Display the employee name and salary for employees who earn the same salary
as the maximum salary. Without using group functions.
ENAME SAL
King11 6500