0

Note that I have similar topics with different questions,

I'm learning MySQL. I came across some multiple-choice questions. If I doubted what the answer was or was not convinced it's correct I started searching google, stackoverflow and the mysql site. However for some I still couldn't confirm what the correct answer was.

Therefore I ask the question here.

Question: Table Employees is created. You want to retrieve the information of those employees who have at least one person reporting to them. Which of the following queries will you execute to accomplish the task?

  • A. SELECT employee_id, last_name, job_id, department_id FROM Employees WHERE employee_id EXISTS(SELECT manager_id WHERE manager_id is NULL);

  • B. SELECT employee_id, last_name, job_id, department_id FROM Employees HAVING employee_id IN(SELECT manager_id FROM Employees WHERE manager_id is NOT NULL);

  • C. SELECT employee_id, last_name, job_id, department_id FROM Employees outer WHERE EXISTS (SELECT 'x' FROM Employees WHERE manager_id = outer.employee_id);

  • D. SELECT employee_id, last_name, job_id, department_id FROM Employees HAVING employee_id WHERE employee_id IN (SELECT manager_id WHERE manager_id is NOT NULL);

    • A and D don't have a FROM clause in the subquery. I guess this is invalid (or just a typo in the question?)
    • The proposed answer is C. However I believe that this can't work because the reserved keyword "outer" is used as an alias here. Please correct me if I'm wrong.
    • So actually only B is left here.
    • Answer D order is incorrect. (WHERE should be before HAVING)
    • Answer A is invalid because the subquery queries for IS NULL.

If you have any remark about this question/answer or for any of my remarks I'm happy to hear it!

4

1 回答 1

0

根据给定的信息,B 似乎是正确的,并更正了应该有 where 而不是任何有 in 语句,但可以更好地告诉您是否上传数据库架构

于 2013-08-18T11:59:11.070 回答