我有两张这样的桌子;
发票
id | total_amount | currency | discount
付款
id | invoice | amount
正如您所猜测的,付款表保存对特定发票的付款记录。
我需要查询以获取已部分支付的发票;
SELECT
invoices.*,
SUM(payments.amount) as paid
FROM
invoices
LEFT JOIN
payments ON payments.invoice = invoices.id
GROUP BY
invoices.id
我能够通过此查询获得付款金额,但我也需要做类似的事情
WHERE paid < total_amount AND paid > 0
但这表示“未知列在‘where 子句’中‘付费’”。我怎样才能得到这份工作?