如何显示部门(一次)和在该部门工作的所有员工的列表?

时间:2015-08-16 05:55:25

标签: sql oracle

对于架构epartments(department_id, department_name) employees(last_name, department_id, salary)
我想显示department_id, department_name, count(employees),avg(salary),last_name,salary
我尝试过使用以下查询

SELECT d1.department_id,d1.department_name,d1."count",d1."avg",e.last_name,e.salary
FROM   employees e
INNER JOIN (SELECT d.department_id,d.department_name,count(e.last_name) AS "count",round(avg(e.salary),2) AS "avg"
                FROM employees e,departments d
                WHERE e.department_id=d.department_id
                GROUP BY d.department_id,d.department_name) d1
    ON e.department_id=d1.department_id;

虽然它显示正确的输出,但它不是我想要的格式。 上面的查询将输出显示为

90  Executive   3   19333.33    King    24000
90  Executive   3   19333.33    Kochhar 17000
90  Executive   3   19333.33    De Haan 17000
60  IT          3   6400        Hunold  9000
60  IT          3   6400        Ernst   6000
60  IT          3   6400        Lorentz 4200
50  Shipping    5   3500        Mourgos 5800

虽然它应该像

90  Executive   3   19333.33    King    24000
                                Kochhar 17000
                                De Haan 17000
60  IT          3   6400        Hunold  9000
                                Ernst   6000
                                Lorentz 4200
50  Shipping    5   3500        Mourgos 5800

0 个答案:

没有答案