Sample Header Ad - 728x90

Comparing an aggregate function's result against a column

1 vote
2 answers
234 views
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 0 But this says "Unknown colum 'paid' in 'where clause'". How can I get this work?
Asked by cem ekkazan (13 rep)
Jan 10, 2024, 06:41 PM
Last activity: Jan 10, 2024, 08:40 PM