0% found this document useful (0 votes)
11 views2 pages

DBMS Query2

The document contains a series of SQL queries designed to extract various employee-related data from an 'EMP' table. These queries include selecting employees with managers, counting employees in departments, calculating salaries, and identifying recent hires among other operations. The queries utilize subqueries, joins, and aggregate functions to provide insights into employee demographics and remuneration.

Uploaded by

23x049
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

DBMS Query2

The document contains a series of SQL queries designed to extract various employee-related data from an 'EMP' table. These queries include selecting employees with managers, counting employees in departments, calculating salaries, and identifying recent hires among other operations. The queries utilize subqueries, joins, and aggregate functions to provide insights into employee demographics and remuneration.

Uploaded by

23x049
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

DBMS QUERY2

1.SELECT E1.Empno, E1.Ename


FROM EMP E1
WHERE EXISTS (SELECT 1 FROM EMP E2 WHERE E2.Mgr = E1.Empno);

2.SELECT *
FROM EMP
WHERE Deptno = 10
AND (SELECT COUNT(*) FROM EMP WHERE Deptno = 10) > 10;

3.SELECT E1.Ename AS Employee, E2.Ename AS Manager


FROM EMP E1
LEFT JOIN EMP E2 ON E1.Mgr = E2.Empno;

4.SELECT E1.Empno, E1.Ename


FROM EMP E1
WHERE NOT EXISTS (SELECT 1 FROM EMP E2 WHERE E2.Mgr = E1.Empno);

5.SELECT *
FROM EMP
WHERE Sal > (SELECT MIN(Sal) FROM EMP WHERE Deptno = 20);

6.SELECT *
FROM EMP
WHERE Sal > (SELECT MAX(Sal) FROM EMP WHERE Empno IN (SELECT DISTINCT Mgr
FROM EMP));

7.SELECT Job, MAX(Sal) AS Highest_Salary


FROM EMP
GROUP BY Job;

8.SELECT Deptno, Ename, Hiredate


FROM EMP
WHERE (Deptno, Hiredate) IN
(SELECT Deptno, MAX(Hiredate)
FROM EMP
GROUP BY Deptno);

9.SELECT EXTRACT(YEAR FROM Hiredate) AS Year, COUNT(*) AS Number_of_Employees


FROM EMP
GROUP BY EXTRACT(YEAR FROM Hiredate)
ORDER BY Number_of_Employees DESC
FETCH FIRST 1 ROWS ONLY;

10.SELECT Deptno, SUM(Sal + NVL(Ccomm, 0)) AS Annual_Remuneration


FROM EMP
GROUP BY Deptno
ORDER BY Annual_Remuneration DESC
FETCH FIRST 1 ROWS ONLY;

11.SELECT Ename, Hiredate,


CASE
WHEN Hiredate = (SELECT MAX(Hiredate) FROM EMP) THEN '*'
ELSE ''
END AS Recent_Hire
FROM EMP;

12.SELECT Empno, Ename, Sal, Deptno


FROM EMP E1
WHERE Sal > (SELECT AVG(Sal) FROM EMP E2 WHERE E1.Deptno = E2.Deptno);

13.SELECT MAX(Sal) AS Second_Max_Salary


FROM EMP
WHERE Sal < (SELECT MAX(Sal) FROM EMP);

14.SELECT Empno, Ename, COUNT(*)


FROM EMP
GROUP BY Empno, Ename, Job, Mgr, Hiredate, Sal, Ccomm, Deptno
HAVING COUNT(*) > 1;

15.SELECT Ename,
TRUNC(MONTHS_BETWEEN(SYSDATE, Hiredate) / 12) AS Years,
MOD(TRUNC(MONTHS_BETWEEN(SYSDATE, Hiredate)), 12) AS Months
FROM EMP;

You might also like