我面臨這個問題,不知道該怎麼做。我有以下問題。 顯示公司中所有部門的名稱以及其經理的姓名。您的查詢必須顯示公司中的所有部門,即使它沒有經理。SQL查詢 - 如何在公司中向經理顯示部門?
我的問題是,當我運行一個查詢只給我部門名稱時,我得到了27個結果。但是對於經理查詢,只有18個結果。
我不知道如何做到這一點。我曾經得到這個查詢是,對於部門名稱:
--select department_name from departments;
Administration
Marketing
Purchasing
Human Resources
Shipping
IT
Public Relations
Sales
Executive
Finance
Accounting
Treasury
Corporate Tax
Control And Credit
Shareholder Services
Benefits
Manufacturing
Construction
Contracting
Operations
IT Support
NOC
IT Helpdesk
Government Sales
Retail Sales
Recruiting
Payroll
第二部分:
select first_name, last_name, department_name from employees e inner join departments d on
d.department_id=e.department_id where (employee_id in (select manager_id from employees));
first_name last_name department_name
Steven King Executive
Neena Kochhar Executive
Lex De Haan Executive
Alexander Hunold IT
Nancy Greenberg Finance
Den Raphaely Purchasing
Matthew Weiss Shipping
Adam Fripp Shipping
Payam Kaufling Shipping
Shanta Vollman Shipping
Kevin Mourgos Shipping
John Russell Sales
Karen Partners Sales
Alberto Errazuriz Sales
Gerald Cambrault Sales
Eleni Zlotkey Sales
Michael Hartstein Marketing
Shelley Higgins Accounting
第二部分只與管理人員返回部門。
答案假設你想學習,而不是讓我們自己做功課,看http://stackoverflow.com/questions/38549/what-is-the-difference-在內部加入和外部加入 –
沒關係球員這是一個外部聯接,我的教授清除了這個!得到它的工作 –