Write the following queries in SQL: a) Retrieve the maximum salary of each emplo
ID: 3777866 • Letter: W
Question
Write the following queries in SQL:
a) Retrieve the maximum salary of each employee in each department.
b) Retrieve the Ssn of all employees who work for the Finance and Research departments.
c) Retrieve the Ssn of all employees who work for any department except the Research department.
d) Retrieve the names of controlling departments of employees who work on more than two projects.
e) Make a list of the distinct names of all employees who are working in department number 4 and employees who are working on projects that are located in Sharjah.
Explanation / Answer
1) select e.fname,e.ssn,e.salary,d.dname from Employee e inner join Department d where e.Dno=d.Dnumber AND e.salary in(select max(salary) from Employee where Dno=d.Dnumber)
3)
select ssn from Employee where Dno in(select Dnumber from Department where dname<>'Research')
2)
select ssn from Employee where Dno in(select Dnumber from Department where dname in('finance','Research'))
4)
select Dname from Department where Dnumber in(select Dno from Employee where ssn in(select Essn from works_on where count(Essn)>2 group by Essn))
5)
select distinct Fname,distinct Lname from Employee where Dno=4 OR ssn in(select Essn from works_on where Pno in(select Pnumber from Project where Plocation='Sharjah'))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.