计数中缺少函数错误

时间:2016-11-22 21:29:55

标签: oracle oracle-sqldeveloper

我有2个数据表,员工和部门。我想显示部门编号,部门名称,每个部门的员工数量,每个部门的平均工资,员工姓名,工资和员工的工作ID。这是我为代码编写的内容:

select d.department_id, d.department_name, e.count(*) Employees,   
avg(e.salary) Avg_salary, e.last_name, e.salary, e.job_id
from departments d join employees e
on d.department_id = e.department_id
group by d.department_id, d.department_name, e.last_name, e.salary, e.job_id 
order by d.department_id;

但是,运行代码时出现错误“Missing Function”。我该如何解决?

2 个答案:

答案 0 :(得分:0)

e.count(*)应为count(*)

编辑:

这是你需要的吗?

COUNT(*) OVER (PARTITION BY e.department_id) DeptCt

答案 1 :(得分:0)

试试这个:

SELECT d.department_id, 
       d.department_name, 
       Count(*)      Employees, 
       Avg(e.salary) Avg_salary, 
       e.last_name, 
       e.salary, 
       e.job_id 
FROM   departments d 
       JOIN employees e 
         ON d.department_id = e.department_id 
GROUP  BY d.department_id, 
          d.department_name, 
          e.last_name, 
          e.salary, 
          e.job_id 
ORDER  BY d.department_id;