10、(5-6) choose the best answer:
Examine the structure of the EMPLOYEES table:
There is a parent/child relationship between EMPLOYEE_ID and MANAGER_ID.
You want to display the name, joining date, and manager for all the employees.
Newly hired employees are yet to be assigned a department or a manager. For them, 'No Manager' should be displayed in the MANAGER column.
Which SQL query gets the required output?
A) SELECT e.last_name, e.hire_date, NVL(m.last_name, 'No Manager') Manager
FROM employees e RIGHT OUTER JOIN employees m
ON (e. manager_id = m.employee_id);
B) SELECT e.last_name, e.hire_date, NVL(m.last_name, 'No Manager') Manager
FROM employees e JOIN employees m
ON (e.manager_id = m.employee_id);
C) SELECT e.last_name, e.hire_date, NVL(m.last_name, 'No Manager') Manager
FROM employees e LEFT OUTER JOIN employees m
ON (e.manager_id = m.employee_id);
D) SELECT e.last_name, e.hire_date, NVL(m.last_name, 'No Manager') Manager
FROM employees e NATURAL JOIN employees m
ON (e.manager_id = m.employee_id);
Answer:C
(解析:因为员工 king 是没有经理的,但是也要显示出来,因为是在经理号这边缺少数据,所以这里要用
左外连接。注意左右的区别:
SELECT e.last_name, e.hire_date, NVL(m.last_name, 'No Manager') Manager
FROM employees e , employees m
WHERE e.manager_id = m.employee_id(+);
)
阅读(905) | 评论(0) | 转发(0) |