Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the table Employees ( id serial, name varchar ( 2 5 5 ) , manager id int ) ; In this table, manager is
Consider the table Employees id serial, name varchar manager id int; In this table, manager is also an employee. Assume the CEO has no manager, but every other employee has one manager. You want to write a query that gives all managers of a given employee with id SELECT eid ename, emanager id FROM employees e INNER JOIN employees e ON elid emanager id AND eid WITH managerchain AS SELECT id name, managerid FROM employees WHERE id UNION ALL SELECT eid ename, emanagerid FROM employees e INNER JOIN managerchain m ON eid mmanagerid SELECT FROM managerchain; SELECT id name, manager id FROM employees WHERE id WITH managerchain AS SELECT id name, manager id FROM employees
Consider the table Employees id serial, name varchar manager id int;
In this table, manager is also an employee. Assume the CEO has no manager, but every other employee has one manager.
You want to write a query that gives all managers of a given employee with id
SELECT eid ename, emanager id FROM employees e INNER JOIN
employees e ON elid emanager id AND eid
WITH managerchain AS
SELECT id name, managerid FROM employees WHERE id
UNION ALL
SELECT eid ename, emanagerid FROM employees e INNER JOIN
managerchain m ON eid mmanagerid
SELECT FROM managerchain;
SELECT id name, manager id FROM employees WHERE id
WITH managerchain AS
SELECT id name, manager id FROM employees
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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