Question
Use the following schema to answer the following question in SQL. Employee(eid, name, office) Manager(eid, mid) Each employee has a unique key, eid. An employee
Use the following schema to answer the following question in SQL.
Employee(eid, name, office) Manager(eid, mid)
Each employee has a unique key, eid. An employee may have several managers, who are, in turn, employees: both attributes eid and mid in Manager(eid, mid) are foreign keys to Employee.
1. Write a query that retrieves all employees that have two or more managers. Your query should return the eid's and the names.
2. An independent employee is an employee without a manager. (For example, the CEO is independent.) Write a query that retrieves all independent employees; you should return their eid and their names.
3. Retrieve the office of all managers of the employee called 'Alice'. If there are multiple employees called Alice, or if one of them has several managers, you have to return all their offices.
4. Find all managers for which all the employees they manage share the same office. Your query should return their eid, their name, and the office where all their managed people are located.
5. A manager is an employee who manages at least one other employee. A second-level manager is a manager who manages only managers. Write a query to return all second-level managers; your query should return their eid's and their names.
Step by Step Solution
3.52 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
1 SELECT eid ename FROM Manager M Employee E WHERE Meid Eeid GROUP BY Eeid Eename HAVING COUN...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started