我有以下SQL语句
Select *
from Policies P
inner join ClientPolicies CP on P.Id = CP.PolicyId
where p.Id <> 0
And P.ProductId = 9
And (
P.PolicyEndDate <= GETDATE()
or
P.PolicyEndDate is null
)
这会拉回与第一个策略日期匹配的所有值小于getdate但不是空值。
答案 0 :(得分:1)
将您的INNER JOIN
更改为LEFT JOIN
:
Select *
from Policies P
left join ClientPolicies CP on P.Id = CP.PolicyId
where p.Id <> 0
And P.ProductId = 9
And (
P.PolicyEndDate <= GETDATE()
or
P.PolicyEndDate is null
)