The retention team wants to understand purchase frequency patterns. Calculate the average, minimum, and maximum gap (in days) between consecutive purchases for each customer.
| Column | Type |
|---|---|
| CustomerId | INTEGER (Primary Key) |
| FirstName | TEXT |
| LastName | TEXT |
| Company | TEXT |
| Address | TEXT |
| City | TEXT |
| State | TEXT |
| Country | TEXT |
| PostalCode | TEXT |
| Phone | TEXT |
| Fax | TEXT |
| TEXT | |
| SupportRepId | INTEGER (Foreign Key → Employee.EmployeeId) |
| Column | Type |
|---|---|
| InvoiceId | INTEGER (Primary Key) |
| CustomerId | INTEGER (Foreign Key → Customer.CustomerId) |
| InvoiceDate | TIMESTAMP |
| BillingAddress | TEXT |
| BillingCity | TEXT |
| BillingState | TEXT |
| BillingCountry | TEXT |
| BillingPostalCode | TEXT |
| Total | NUMERIC(10,2) |
LAG() to get each customer's previous invoice dateEXTRACT(EPOCH FROM (a - b)) / 86400AvgDaysBetween, MinGap, MaxGap, PurchaseCountReady 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.