0% found this document useful (0 votes)
13 views4 pages

SQL Mastery Set 3

The document contains a series of SQL queries related to employee data management, focusing on various employee attributes such as department, job title, salary, and hire date. It includes examples of optimized queries using joins and Common Table Expressions (CTEs). Additionally, it provides links to further resources for data engineering interview preparation.

Uploaded by

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

SQL Mastery Set 3

The document contains a series of SQL queries related to employee data management, focusing on various employee attributes such as department, job title, salary, and hire date. It includes examples of optimized queries using joins and Common Table Expressions (CTEs). Additionally, it provides links to further resources for data engineering interview preparation.

Uploaded by

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

SQL Mastery Series – 110 Question using 4 table – Set 3

Emp Table:

DEPT

Salgrade

JobHistory
-- 17) Display the names of employees who work in the same
department as ‘SMITH’ and dont include smith.
SELECT ENAME
FROM EMP
WHERE DEPTNO = (
SELECT DEPTNO
FROM EMP
WHERE ENAME = 'SMITH'
)
AND ENAME != 'SMITH';

--Optimized way using joins


SELECT E1.ENAME
FROM EMP E1
JOIN EMP E2 ON E1.DEPTNO = E2.DEPTNO
WHERE E2.ENAME = 'SMITH'
AND E1.ENAME != 'SMITH';

--USing CTE
WITH SmithDept AS (
SELECT DEPTNO
FROM EMP
WHERE ENAME = 'SMITH'
)
SELECT ENAME
FROM EMP
WHERE DEPTNO = (SELECT DEPTNO FROM SmithDept)
AND ENAME != 'SMITH';

-- 18) Display the names of employees who do the same job as


‘ALLEN’.
SELECT ENAME
FROM EMP
WHERE JOB = (
SELECT JOB
FROM EMP
WHERE ENAME = 'ALLEN'
);
--Give optimized query in comment

-- 19) Find employees whose job title contains the letter ‘M’.
SELECT ENAME , Job
FROM EMP
WHERE JOB LIKE '%M%';

-- 20) Display the details of employees whose salary is between


1000 and 2000.
SELECT *
FROM EMP
WHERE SAL BETWEEN 1000 AND 2000;

-- 21) Find employees who joined in the year 1981.


SELECT ENAME, HIREDATE
FROM EMP
WHERE YEAR(HIREDATE) = 1981;
-- 22) Find employees whose salary is higher than their manager's
salary.
SELECT E.ENAME
FROM EMP E
JOIN EMP M ON E.MGR = M.EMPNO
WHERE E.SAL > M.SAL;

--Using CTE
WITH ManagerSalaries AS (
SELECT EMPNO, SAL
FROM EMP
)
SELECT E.ENAME
FROM EMP E
JOIN ManagerSalaries M ON E.MGR = M.EMPNO
WHERE E.SAL > M.SAL;

Check out 200+ scenario based databricks and pyspark Scenario based Question in
Topmate: https://topmate.io/shivakiran_kotur/1376452

Check out 200+ Python Question and Answer for Data Engineer asked in Interview in
Topmate: https://topmate.io/shivakiran_kotur/1337666

You might also like