【发布时间】:2016-02-10 15:44:47
【问题描述】:
我正在尝试显示行,即使它们返回的计数为零。然而没有运气。 我尝试使用左连接。
select
a.Month,
count(b.InsuranceFromJob) [Number of Participants without Insurance]
from
hsAdmin.ReportPeriodLkup a
left join hsAdmin.ClientReport b on
b.ReportPeriod = a.ReportPeriodId
where
b.insurancefromjob = 2 and
a.reportperiodid between (@lastReportId - 11) and @lastReportId
group by
a.Month
【问题讨论】:
-
尝试在 count 中使用
coalesce或zeroifnull命令。请提及数据库名称。 -
您在
WHERE子句中对表别名b有限制,因此您有效地将LEFT OUTER JOIN变成了INNER JOIN。 -
尝试将谓词
b.insurancefromjob = 2移动到ON子句 -
谢谢@GiorgosBetsos 成功了。