Skip to content

1677. Product's Worth Over Invoices 👎

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SELECT
  Product.name,
  IFNULL(SUM(Invoice.rest), 0) AS rest,
  IFNULL(SUM(Invoice.paid), 0) AS paid,
  IFNULL(SUM(Invoice.canceled), 0) AS canceled,
  IFNULL(SUM(Invoice.refunded), 0) AS refunded
FROM Product
LEFT JOIN Invoice
  USING (product_id)
GROUP BY 1
ORDER BY 1;