How many days in between?
Sales arrive irregularly. For each invoice in date order, compute days_since_last: the gap in days between it and the previous invoice. julianday() turns a date into a number you can subtract. The first invoice has no predecessor — a NULL there is correct, not a bug.
Tables in this exercise
invoices
id customer_id invoice_date billing_city billing_country total