Chapter 9 · Interview Level
30. Revenue Pivot by Payment Method
Hard40 XPE-Commerce
Create a pivot report showing total revenue per month broken down by payment method. Each payment method should be its own column. Use CASE expressions inside SUM to achieve the pivot. Assume methods include 'credit_card', 'debit_card', 'paypal', and 'bank_transfer'. Also return a total column. Format months as YYYY-MM and sort by month.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- order_dateTEXT
- statusTEXT
- total_amountREAL
- PKidINT
- FKorder_id→ orders.idINT
- payment_dateTEXT
- amountREAL
- methodTEXT
- statusTEXT
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.