我想将此案别名为 Brutobedrag,但我无法完成。
SELECT
Invoices.InvoiceNr AS Factuurnummer,
case(Invoices.IsDebit)
when 0 then -1*(Invoices.NetAmount + Invoices.BTW + COALESCE (Invoices.BPM, 0))
else Invoices.NetAmount + Invoices.BTW + COALESCE (Invoices.BPM, 0)
end
from
Brands INNER JOIN
Invoices ON Brands.Id = Invoices.Brand INNER JOIN
SalesPersons ON Invoices.SalesPerson = SalesPersons.Id LEFT OUTER JOIN
Payments ON Invoices.Id = Payments.InvoiceId
where
Invoices.InvoiceDate > '2011-12-31'
group by
Invoices.InvoiceNr,
Invoices.NetAmount,
invoices.BTW,
invoices.BPM,
Invoices.IsDebit