0

我之前在 SQL Server 中创建了这个 SELECT 命令,它需要计算每个部门包含多少员工。这是我使用的:

SELECT Departments.Description AS [Department], COUNT(Employees.ID) AS [Employees]
FROM Employees 
RIGHT JOIN Departments ON
Employees.DepartmentID = Departments.ID 
GROUP BY Departments.Description

它工作正常(即使没有员工,也显示部门)。

现在,我只想通过以下过滤器计算当前工作的员工:

WHERE Employees.JobEndDate = null

我试着这样做:

SELECT   Departments.Description AS [Department], COUNT(Employees.ID) AS [Employees] 
FROM Employees 
RIGHT JOIN Departments ON
Employees.DepartmentID = Departments.ID 
WHERE Employees.JobEndDate = NULL 
GROUP BY Departments.Description

但现在我没有得到任何结果。知道我做错了什么吗?

谢谢 :) 米西。

4

2 回答 2

4

测试字段返回值是否NULL不是通过=等号而是通过IS运算符执行的

= null

不起作用,而是写:

Employees.JobEndDate IS NULL
于 2012-05-27T17:48:45.593 回答
0
SELECT Departments.Description AS [Department], COUNT(Employees.ID) AS [Employees] FROM Employees RIGHT JOIN Departments ON Employees.DepartmentID = Departments.ID WHERE Employees.JobEndDate = IS NULL GROUP BY Departments.Description
于 2012-05-27T17:52:19.313 回答