Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Select
- Customer_ID
- ,row_number() over (partition by Customer_ID order by date) r_num
- ,date
- ,total_paid
- Into #Customer_Transactions
- From Customer_Transactions
- Select
- t1.Customer_ID
- ,datediff(dd,t1.date ,t2.date) --this will calculate the difference in days
- From #Customer_Transactions t1
- Join #Customer_Transactions t2
- ON t1.Customer_ID = t2.Customer_ID
- And t1.r_num = t2.r_num+1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement