我有两张桌子:
tbl_Invoice
tbl_payment
当我通过 client_Id = 时5
,所需的输出应该是:
PSUM IPRICE Amt_Type
----------- -------------- ----------------
100.00 100.00 USD
0.00 1000.00 GBP
在哪里
PSUM
是总付款的总和
IPRICE
是发票总价格的总和
我尝试过的是:
Select SUM(P.Amt) as PSUM, SUM(I.Total_price) as IPRICE, I.Amt_Type from
[tbl_payment] P left join [tbl_Invoice] I on P.invoice_Id = I.invoice_Id
WHERE P.client_id = @Client_Id and I.client_id = @Client_Id
group by I.Amt_Type