i have 2 tables like these;
invoices
id | total_amount | currency | discount
payments
id | invoice | amount
As you can guess, payments table keeps records of the payment made to a specific invoice.
I need a query to get invoices that has been partially paid;
SELECT
invoices.*,
SUM(payments.amount) as paid
FROM
invoices
LEFT JOIN
payments ON payments.invoice = invoices.id
GROUP BY
invoices.id
I am being able to get paid amount with this query but also i need to do something like
WHERE paid < total_amount AND paid > 0
But this says "Unknown colum 'paid' in 'where clause'". How can I get this work?