当没有FLI匹配查询但有租约时如何显示0

问题描述 投票:0回答:1

说,我们有两个表。Table 1 with Lease and Table 2 with Amounts

查询时间= 2019-02。它必须仅显示以下格式的有效租赁:Expected output

但是,变得像:current output

如何将查询期为NULL的租约ID显示为0。

db2
1个回答
0
投票

您可以使用left join

select l.leaseid, coalesce(a.amount, 0)
from lease l left join
     amount a
     on a.leaseid = l.leaseid and a.period = '2019-02'
where l.status = 'active';
© www.soinside.com 2019 - 2024. All rights reserved.