name column from the Product table.LEFT JOIN with the Invoice table on the product_id column to include all products.SUM function to calculate the total rest, paid, canceled, and refunded amounts for each product.IFNULL or COALESCE function to replace nulls with zeros in the aggregated sums.product_id to ensure aggregation is done per product.name of the product to meet the requirement of the problem statement.
erDiagram
Product {
int product_id PK
varchar name
}
Invoice {
int invoice_id PK
int product_id FK
int rest
int paid
int canceled
int refunded
}
Product ||--o{ Invoice : has