我已經使用了兩張表的發票和付款。 我試圖產生付費,到期和無償狀態。應用mysql條件
以下是我的查詢,這將給所有發票和總付款。 如何應用條件來過濾已付款,到期,未付款。 我不能給作爲支付的金額 以下是成功的查詢:
select a.*, sum(b.amount) as paidamount from tbl_invoices a left join tbl_billpayment b on a.invoiceno = b.invoiceno where a.id != '' GROUP BY b.invoiceno ORDER BY a.billdate DESC LIMIT 0,10
這將給錯誤
select a.*, sum(b.amount) as paidamount from tbl_invoices a left join tbl_billpayment b on a.invoiceno = b.invoiceno where a.id != '' and (paidamount >= a.total)
Notice: Error: Unknown column 'paidamount' in 'where clause'
感謝您的支持
HAVING sum(b.amount)> = a.total會給我付出的結果,謝謝! –
其實@dragoste的回答也是正確的.. – Ali786