我有一个 mysql 查询来获取要接收的发票付款总额:
SELECT
SUM(amount * ((vat / 100) + 1)) AS total
FROM invoices
WHERE status = 'send' AND date_paid = 0
我还有一张存储收到的金额的表格。如何处理部分支付的发票,以便我可以看到收到的真实金额?我正在使用一个表来存储名为 payment_rev 的付款以及列 invoice_id 和金额。
我努力了:
SELECT
SUM(amount * ((vat / 100) + 1)) AS total,
SUM(pd.amount) AS total_paid
FROM invoices AS inv
LEFT JOIN 11_invoices_paid AS pd
ON pd.inv_id = inv.id
WHERE inv.status = 'send' AND inv.date_paid = 0
GROUP BY inv.id
结果它给出了 total_paid = 0 ??
CREATE TABLE IF NOT EXISTS `invoices` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`dossier_id` int(6) NOT NULL,
`invoice_no` int(5) NOT NULL,
`amount_excl` decimal(8,2) NOT NULL,
`vat` int(2) NOT NULL,
`date_send` date NOT NULL,
`date_pay` date NOT NULL,
`date_paid` date NOT NULL,
`status` varchar(10) NOT NULL
PRIMARY KEY (`id`)
)
CREATE TABLE IF NOT EXISTS `invoices_paid` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`invoice_id` int(6) NOT NULL,
`amount` decimal(8,2) NOT NULL,
`date` date NOT NULL
PRIMARY KEY (`id`)
)