Sql 如何使用此代码的逐组函数

Sql 如何使用此代码的逐组函数,sql,oracle,oracle-sqldeveloper,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.c

这段代码在语法上是真的吗?但它在我的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;

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

      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,因此不清楚您提出了什么问题,但这可能是一个解决方案

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

按国家/地区。国家/地区只需使用
JOIN
而不是在
WHERE
中使用,你能解释一下你想做什么吗?您可以在末尾添加GROUP BY子句,只需添加
GROUP BY locations.country\u id、locations.street\u address、departments.department\u name
,但我感觉这不是您真正想要实现的。请添加当前输入和输出的示例数据:使用表别名来保存一些键入。(也使查询更容易阅读。)这里我无法分组,按国家/地区。@KanbarzadehNurlan您没有使用任何聚合函数,所以为什么需要分组依据?@KanbarzadehNurlan共享您的表数据和预期输出,这很容易正确指导。这是oracle默认表。如果您不添加示例数据和预期输出,将很难理解您想要什么,这是sql开发人员的默认设置表。我们没有您需要的输出,请添加输出,所以我们不知道,即使我们有数据,您想去哪里