我正在尝试在查询中包括终止日期可以追溯到6个月之前的所有员工,同时还包括在职员工。我包括以下内容,但这样做是在过滤掉在职员工。我该如何实现?
JOIN Employees1 e
ON e.ClientID = c.ClientID
JOIN Employees2 d
ON d.ClientID = e.ClientID
AND d.EmployeeUID = e.EmployeeUID
AND TerminationDate >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -6,current_timestamp)), 0)
“ joins
中包含逻辑,请尝试如下操作:SELECT
e.*
FROM
Employees1 e
WHERE
e.TerminateDate IS NULL
UNION ALL
SELECT
e1.*
FROM
Employees1 e1
WHERE
e1.TerminateDate >= DATEADD(m, -6, GetDate())
甚至更好,请参阅Gordon Linoff的回答。
OR
子句中使用FROM
:select e.*
from employees e
where e.TerminationDate >= DATEADD(month, -6, current_timestamp) OR
e.TerminationDate IS NULL;