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

Gokul

The document contains the solutions to a lab assessment with 10 SQL queries related to retrieving employee, department, and project information from various tables in a relational database schema. The queries find highest paid employees, employees with minimum salaries, average salaries by department, and create views and tables to store and display different subsets of data.

Uploaded by

Sathvik Muppidi
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)
46 views4 pages

Gokul

The document contains the solutions to a lab assessment with 10 SQL queries related to retrieving employee, department, and project information from various tables in a relational database schema. The queries find highest paid employees, employees with minimum salaries, average salaries by department, and create views and tables to store and display different subsets of data.

Uploaded by

Sathvik Muppidi
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

NAME: Sanjay kasi Ramesh

REG NO.: 21BCE3436


LAB ASSESSMENT – 3
Exercise – 1
For the relational schema given as part of Assessment – 1, write the SQL queries to get the following
information.
1) Find the employee who is getting highest salary in the department research
2) Find the employees who earn the same salary as the minimum salary for each Department
3) Find the employee whose salary is greater than average salary of department 2
4) List out all the department names with their individual employee’s strength
5) Find out the department name having highest employee strength
6) List out all the departments and average salary drawn by their employees
7) Find maximum average salary for each department.
8) Create a view to display the employee details who is working in IT department.
9) Create a logical table to store employee details who is getting salary more than 10000.
10) Create a table to store the employees details based on the department no.

Q1) SELECT e.* FROM employee e


JOIN dept d ON e.Depno = d.Depno
WHERE d.dname = 'Research' AND e.Salary = (SELECT MAX(Salary) FROM employee WHERE Depno =
d.Depno);

Q2) SELECT e.* FROM employee e


JOIN ( SELECT depno, MIN(salary) AS min_salary
FROM employee GROUP BY depno )
min_salaries ON e.depno = min_salaries.depno
WHERE e.salary = min_salaries.min_salary;

Q3) SELECT * FROM employee


WHERE salary > (SELECT AVG(salary) FROM employee WHERE Depno = 2);

Q4) SELECT d.dname, COUNT(e.lname) as employee_count FROM dept d


LEFT JOIN employee e ON d.depno = e.depno
GROUP BY d.dname;

Q5) SELECT d.dname, COUNT(e.lname) as employee_count FROM dept d


LEFT JOIN employee e ON d.depno = e.depno GROUP BY d.dname
HAVING COUNT(e.lname) = (
SELECT MAX(emp_count)
FROM (
SELECT COUNT(lname) AS emp_count
FROM employee GROUP BY depno
) );

Q6) SELECT d.dname, AVG(e.salary) as average_salary


FROM dept d
LEFT JOIN employee e ON d.depno = e.depno
GROUP BY d.dname;
Q7) SELECT d.dname, subquery.max_avg_salary FROM dept d
JOIN ( SELECT depno, MAX(average_salary) as max_avg_salary
FROM ( SELECT depno, AVG(salary) as average_salary
FROM employee GROUP BY depno)
sub GROUP BY depno )
subquery ON d.depno = subquery.depno;

Q8) CREATE VIEW IT_Employees AS


SELECT * FROM employee
WHERE depno = (
SELECT depno
FROM dept WHERE dname = 'IT'
);

Q9) CREATE VIEW logical_table AS


SELECT * FROM employee
WHERE salary > 10000;

Q10) CREATE VIEW DepartmentEmployees AS


SELECT * FROM employee
ORDER BY depno;

Exercise – 2
For the relational schema given as part of Assessment – 1, write the SQL queries using joins to get the following
information.
1) Retrieve the names of all employees in department 5 who work more than 10 hours per week on ProductX
project.
2) List the names of all employees who have a dependent with the same first name as themselves.
3) Find the names of all the employees who are directly supervised by ‘Franklin Wong’.
4) Retrieve the names of all who do not work on any project.
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.
6) List the names of all managers who have no dependents.
7) List the employee’s names and the department names if they happen to manage a department.
8) For each project retrieve the project number, project name and the number of employees who work on that
project.
9) For each project, list the project name and the total hours per week (by all employees) spent on that project.
10) Retrieve the names of the employees who have 2 or more dependents.

Q1) SELECT e.fname, e. mname, e.lname, e.ssn, e.depno FROM employee e


JOIN works_on w ON e.ssn = w.essn
JOIN project p ON e.depno = p.depno
WHERE e.depno = 5
AND p.pname = 'ProductX'
AND w.hours > 10;
Q2) SELECT e.fname, e.mname, e.lname
FROM employee e
JOIN dependent d ON e.ssn = d.essn
WHERE e.fname = d.dependent_name;

Q3) SELECT e.fname, e.lname


FROM employee e
JOIN employee fw ON e.superssn = fw.ssn
WHERE fw.fname = 'Frankin' AND fw.lname = 'Wong';

Q4) SELECT fname, lname


FROM employee
WHERE ssn NOT IN (SELECT essn FROM works_on);

Q5) SELECT e.fNAME, e.lNAME, e.ADDRESS FROM EMPLOYEE e


WHERE EXISTS ( SELECT * FROM WORKS_ON w, PROJECT p WHERE e.SSN=w.ESSN AND w.PNO=p.PNUMBER
AND p.pLOCATION='Houston' )
AND NOT EXISTS ( SELECT * FROM DEPT_LOCATIONS d WHERE e.Depno=d.DepNo AND
d.DLOCATION='Houston' ) ;

Q6) SELECT e.FName, e.Lname FROM EMPLOYEE e WHERE EXISTS (


SELECT * FROM DEPT d WHERE e.SSN=d.MGRSSN)
AND NOT EXISTS ( SELECT *FROM DEPENDENT WHERE SSN=ESSN );

Q7) SELECT e.fname, e.lname, d.dname


FROM employee e
JOIN dept d ON e.ssn = d.mgrssn;

Q8) SELECT PNUMBER, PNAME, COUNT (*)


FROM PROJECT, WORKS_ON
WHERE PNUMBER=PNO
GROUP BY PNUMBER, PNAME ;

Q9) SELECT PNAME, SUM (HOURS) FROM PROJECT, WORKS_ON


WHERE PNUMBER=PNO
GROUP BY PNAME;

Q10) SELECT FNAME, LNAME FROM EMPLOYEE


WHERE(SELECT COUNT (*) FROM DEPENDENT
WHERE SSN = ESSN) >= 2;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy