mysql
我的脚本有问题。
我有 2 张桌子,我想在另一张桌子上比较我invoiceAmount
的。paymentAmount
情况是:一张发票可以有很多付款,我想invoiceAmount (table A)
与paymentAmount (table B)
.
我已经用paymentAmount
相同的 invoiceID 计算加入了它,我的问题是如何比较它(所有行的两个表中相同 invoiceID 的总和)paymentAmount(table B)
?invoiceAmount (table A)
真的需要你们的帮助。。
我的脚本是:
SELECT invoice.InvoiceID, invoice.InvoiceAmount, pays.InvoiceID, sum(pays.PaymentAmount) as pays, invoice.InvoiceDate
FROM `payment from customer` as pays
JOIN invoice ON(pays.InvoiceID=invoice.InvoiceID)
WHERE pays.InvoiceID in (
SELECT InvoiceID
FROM `payment from customer`
GROUP BY InvoiceID
HAVING count(*) > 1)
GROUP BY pays.InvoiceID