如何选择 employeeId
为空值且 employeeId
不为空值的所有部门?
部门
id employeeID
1 1
1 null
2 2
3 null
结果应该是department id - 1
最佳答案
select id
from department
group by id
having count(employeeId) between 1 and count(*)-1
count(employeeId)
计算非 NULL employeeId
- 如果大于 0,则表示我们至少有一个 NOT NULL 值。
- 如果它是 < count(*) 这意味着我们至少有一个 NULL 值。
关于mysql - 选择 employeeId 为空且不为空的所有部门?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42992108/