如何针对此代码使用按功能分组

时间:2018-10-19 14:44:50

标签: sql oracle oracle-sqldeveloper

此代码在语法上是否正确?但这在我的SQL开发人员中不起作用

SELECT
    locations.country_id,
    locations.street_address,
    departments.department_name
FROM
    departments
    JOIN locations ON departments.location_id = locations.location_id
    JOIN countries ON locations.country_id = countries.country_id
    JOIN employees ON departments.manager_id = employees.manager_id
GROUP BY
    locations.country_id;

2 个答案:

答案 0 :(得分:0)

使用显式联接,用逗号分隔的表将创建交叉联接,因此请按如下所示更改联接

      SELECT locations.country_id,
      locations.street_address,departments.department_name
     FROM
     departments join
     locations on departments.location_id = locations.location_id
     join countries on locations.country_id    = countries.country_id
     join employees on departments.manager_id=employees.manager_id

由于您没有使用任何聚合函数,因此不需要分组依据

答案 1 :(得分:0)

不清楚您要问什么,但这可能是解决方案

SELECT locations.country_id,locations.street_address,departments.department_name 
FROM
departments,
locations,
countries,
employees
WHERE
employees.department_id = departments.department_id
AND locations.country_id    = countries.country_id
AND departments.location_id = locations.location_id
AND departments.manager_id=employees.manager_id;
GROUP BY locations.country_id, departments.department_name