Imagine you're working as a financial analyst for an e-commerce company that needs to analyze their invoice data across all products. You have access to two important databases:
- Product Database: Contains all products with their unique IDs and names
- Invoice Database: Contains detailed financial information for each invoice including amounts that are still owed, paid, canceled, or refunded
Your task is to create a comprehensive financial report that shows, for each product, the total amounts across all four financial categories from all invoices associated with that product.
Goal: Generate a summary report showing each product's name along with the total amounts due (rest), paid (paid), canceled (canceled), and refunded (refunded) across all invoices.
Input: Two tables - Product table with product information and Invoice table with financial transaction details.
Output: A result set with product names and their aggregated financial totals, ordered alphabetically by product name.
Input & Output
Constraints
- 1 โค number of products โค 104
- 0 โค number of invoices โค 105
- Product names contain only lowercase English letters
- All financial amounts are non-negative integers
- Each product_id in Product table is unique
- Each invoice_id in Invoice table is unique