For each of a customer's invoices, show the Total of their next invoice (chronologically) and the change between the two.
Return CustomerId, InvoiceId, InvoiceDate, Total, NextInvoiceTotal, and TotalChange, ordered by CustomerId then InvoiceDate.
Note: a customer's last invoice will have NULL for both new columns -- there's no next invoice to compare against. Expected, not a bug.
| Column | Type |
|---|---|
| InvoiceId | INTEGER (Primary Key) |
| CustomerId | INTEGER (Foreign Key) |
| InvoiceDate | TIMESTAMP |
| Total | NUMERIC(10,2) |
Ready to take your skills to the next level? Enroll in our comprehensive Data Analyst Career Track to master SQL, Python, Excel, and Power BI.
Run your code to see the result here.