使用非数值时无效的数字错误

时间:2016-11-09 04:33:56

标签: sql oracle

我有2个表,部门和员工。我想在任何员工少于4人的部门中显示department_id,department_name和员工人数。

这是我正在使用的代码(我使用SQL开发人员,顺便说一句):

select d.department_id, d.department_name, count(e.last_name)
from departments d, employees e
where e.last_name < 4
group by d.department_id, d.department_name;

但是,我收到的数字错误无效。这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

这样的事情会更有意义:

SELECT d.department_id,
       d.department_name,
       COUNT(*) AS numEmployees
FROM departments d
INNER JOIN employees e
    ON d.department_id = e.department_id
GROUP BY d.department_id,
         d.department_name
HAVING COUNT(*) < 4