Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given the below database: employee(employee-name, street, city) works(em

ID: 3605581 • Letter: Y

Question

You are given the below database:

employee(employee-name, street, city)

works(employee-name, company-name, salary)

company(company-name, city)

manages(employee-name, manager-name)

Give an expression in SQL for each of the following queries:

Find the names, street address, and cities of residence for all employees who work for 'First Bank Corporation' and earn more than $10,000.

Find the names of all employees in the database who live in the same cities as the companies for which they work.

Find the names of all employees in the database who live in the same cities and on the same streets as do their managers.

Find the names of all employees in the database who do not work for 'First Bank Corporation'. Assume that all people work for exactly one company.

Find the names of all employees in the database who earn more than every employee of 'Small Bank Corporation'. Assume that all people work for at most one company.

Assume that the companies may be located in several cities. Find all companies located in every city in which 'Small Bank Corporation' is located.

Find the names of all employees who earn more than the average salary of all employees of their company. Assume that all people work for at most one company.

Explanation / Answer

Find the names, street address, and cities of residence for all employees who work for 'First Bank Corporation' and earn more than $10,000.
Ans:
select * from employee where employee-name in
(select employee-name from works where company-name = ’First Bank Corporation’ and salary =10000);

Find the names of all employees in the database who live in the same cities as the companies for which they work.
Ans:
select e.employee-name from employee e, works w, company c where e.employee-name = w.employee-name and e.city = c.city and
w.company-name = c.company-name;


Find the names of all employees in the database who live in the same cities and on the same streets as do their managers.
Ans:
select P.employee-name from employee P, employee R, manages M
where P.employee-name = M.employee-name and M.manager-name = R.employee-name and
P.street = R.street and P.city = R.city;

Find the names of all employees in the database who do not work for 'First Bank Corporation'. Assume that all people work for exactly one company.

Ans:
select employee-name from works
where company-name !=’First Bank Corporation’;

Find the names of all employees in the database who earn more than every employee of 'Small Bank Corporation'. Assume that all people work for at most one company.
Ans:
select employee-name from works where salary > all
(select salary from works where company-name = ’Small Bank Corporation’);


Assume that the companies may be located in several cities. Find all companies located in every city in which 'Small Bank Corporation' is located.
Ans:
select T.company-name from company T where (select R.city
from company R where R.company-name = T.company-name)
contains (select S.city from company S
where S.company-name = ’Small Bank Corporation’)
;

Find the names of all employees who earn more than the average salary of all employees of their company. Assume that all people work for at most one company.
Ans:
select employee-name from works T
where salary > (select avg (salary)
from works S where T.company-name = S.company-name);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote