21bce0400 Ass3
21bce0400 Ass3
Assessment -3
Query:
SELECT * FROM Employee WHERE Salary = ( SELECT MAX(Salary) FROM Employee WHERE
Department_Number = ( SELECT Department_Number FROM Dept WHERE Department_Name =
'Research' ));
Output:
2) Find the employees who earn the same salary as the minimum salary for each Department.
Query:
GROUP BY D.DEPARTMENT_NUMBER) M
ON E.DEPARTMENT_NUMBER = M.DEPARTMENT_NUMBER
Output:
3) Find the employee whose salary is greater than average salary of department 2.
Query:
SELECT *
FROM Employee
WHERE SALARY > (SELECT AVG(SALARY) FROM Employee WHERE DEPARTMENT_NUMBER = 2);
Output:
Reason:
Because there was only one employee whose department number was 2 but in assessment 2 the
department number of that employee was modified to 2 . Hence , no data found.
4) List out all the department names with their individual employees strength.
Query:
FROM dept D
GROUP BY D.DEPARTMENT_NAME;
Output:
5) Find out the department name having highest employee strength
Query:
FROM dept D
GROUP BY D.DEPARTMENT_NAME
HAVING COUNT(E.SSN_NUMBER) = (
SELECT MAX(COUNT(E2.SSN_NUMBER))
FROM dept D2
GROUP BY D2.DEPARTMENT_NAME
);
Output:
6) List out all the departments and average salary drawn by their employees.
Query:
GROUP BY D.DEPARTMENT_NAME;
Output:
7) Find maximum average salary for each department.
Query:
HAVING AVG(E.SALARY) = (
SELECT MAX(AVG_SALARY)
Output:
Query:
Output:
To view employee details:
Query:
Output:
Reason:
9) Create a logical table to store employee details who is getting salary more than 10000.
Query:
Output:
To view Details:
Query:
10) Create a table to store the employees details based on the department no.
Query:
FROM Employee e
Output:
To display:
Query:
Output:
EXERCISE 2
1) Retrieve the names of all employees in department 5 who work more than 10 hours per week
on ProductX project.
Query:
Output:
2) List the names of all employees who have a dependent with the same first name as themselves.
Query:
FROM employee e
Output:
3) Find the names of all the employees who are directly supervised by ‘Franklin Wong’.
Query:
FROM employee e
Output:
Query:
FROM employee e
Output:
5) Find the names and addresses of all employees who work on at least one project located in
Houston but whose department has no location in Houston.
Query:
Output:
Query:
Output:
7) List the employee’s names and the department names if they happen to manage a department.
Query:
FROM employee e
8) For each project retrieve the project number, project name and the number of employees who
work on that project.
Query:
FROM project p
Output:
9) For each project, list the project name and the total hours per week (by all employees) spent on
that project.
Query:
FROM project p
Output:
10) Retrieve the names of the employees who have 2 or more dependents.
Query:
Output: