有人要求我创建一个包含两个Tabe部门和员工的完全外部联接的视图,如下所示:
创建一个新的视图名称作为全视图。获取以下列:MIN(LASTNAME)名称作为名称,不重复(manager_id)重命名为“ Available Manager_id”,计数(manager_id)重命名为“否”。 Manager_id”,以及每个job_id的总和(薪水)。应用完全外部联接
由于有人要求对每个job_id求和(薪水),因此我认为需要按分组使用,但我不知道如何使用。我非常感谢有人可以帮助我解决以下有关上述问题的陈述:>
CREATE VIEW FULLVIEW
AS (
SELECT MIN(LASTNAME) AS NAME,
DISTINCT(E.MANAGER_ID) AS "Available Manager_id",
COUNT(E.MANAGER_ID) AS "No.of Manager_id",
JOB_ID,
sum(salary)
FROM EMPLOYEES E
FULL OUTER JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
GROUP BY JOB_ID);
答案 0 :(得分:0)
我为该问题找到的一个可能的正确答案如下:
CREATE VIEW fullview
AS
( SELECT DISTINCT (d.manager_id) AS "Available Manager_id",
MIN (lastname) AS name,
COUNT (d.manager_id) AS "No.of Manager_id",
job_id,
SUM (salary) AS salary
FROM employees e
FULL OUTER JOIN departments d ON e.manager_id = d.manager_id
GROUP BY e.job_id, d.manager_id);