select offices.office_id,
count(staff_id)
from offices join staffs using (office_id) join managers using (manager_id)
group by office_id;
我一直在获取
ERROR at line 1: ORA-25154: column part of USING clause cannot have qualifier.
我正在尝试计算不同办公室的员工总数。在这里,我按办公室 ID 对结果进行了分组。这里出了什么问题。
但如果我喜欢这样
select count(staff_id)
from offices join staffs using (office_id) join managers using (manager_id)
group by office_id;
它以这种方式工作,并且只显示一列,因为我删除了 offices.office_id 列
。但我需要办公室 ID 及其相应的员 worker 数并排在两列中。
最佳答案
在查询中使用 USING
子句时,指定表名称是多余的。对于数据库来说,只有列名就足够了。例如 - 选择 office_id
。试试这个:
select office_id,
count(staff_id)
from offices join staffs using (office_id) join managers using (manager_id)
group by office_id;
引用这个类似的问题:Cannot have a qualifier in the select list while performing a JOIN w/ USING keyword
关于sql - 无法使用 GROUP BY 子句对 ORACLE 中的数据进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20813608/