如何使用 Balance 列的 where 子句过滤以下查询中的数据。当我在 where 条件下使用 Balance 时,出现错误 [“where 子句”中的未知列“Balance”]。
select *,(it.Total - p.Amount) as Balance
from invoices i
left outer join invoice_items it
on i.ID=it.InvoiceID
left outer join payment p
on p.InvoiceID=it.InvoiceID
where Balance!=0;
而且,当没有找到匹配的付款记录时,我不需要在 Balance 列中显示空值,而是需要 invoice_items 表的 Total 值。