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