For every invoice, assign a sequential number within its customer, ordered by InvoiceDate -- so each customer's first invoice is 1, their second is 2, and so on.
Return CustomerId, InvoiceId, InvoiceDate, and InvoiceNumber, ordered by CustomerId then InvoiceNumber.
| Column | Type |
|---|---|
| InvoiceId | INTEGER (Primary Key) |
| CustomerId | INTEGER (Foreign Key) |
| InvoiceDate | TIMESTAMP |
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.