Florian Heinrich

is there any solution for this problem? i have 3 tables customers, orders, payments and i want total bill and payment for each customer in a table

admin

query=>>

SELECT c_id,
       c_name, 
       c_contact, 
       SUM(o_quantity*o_price) AS bill, 
       SUM(p_total_payment) AS paid, 
       SUM((o_quantity*o_price)-(p_total_payment))
FROM orders 
LEFT JOIN payments ON o_customer_id = p_customer_id 
LEFT JOIN customers ON o_customer_id = c_id
GROUP BY o_customer_id

Exit mobile version