This is a much simplified table but the process should be the same. I want to calculate the amount of days between logins. Here is the table set-up query.
create table tester (user_id int, login_day date);
insert into tester (user_id,login_day)
values
(1,'2013-10-02'),
(1,'2013-10-05'),
(2,'2013-10-03'),
(2,'2013-10-04'),
(2,'2013-10-07');
To give this:
user_id; login_day
1; "2013-10-02"
1; "2013-10-05"
2; "2013-10-03"
2; "2013-10-04"
2; "2013-10-07"
The results table should be like this:
user_id; login_day; tau
1;"2013-10-02"; 2
1;"2013-10-05"; 1 --see edit
2;"2013-10-03"; 0
2;"2013-10-04"; 2
2;"2013-10-07"; 0
Where tau is the difference in days-1. User_id(1) logged in on the 2nd and the 5th. So their tau value is 2 since it was two days between logins.
User_id(2) has a value of 0 since they logged in on consecutive days.
The 7th gets a 0 since no time has passed. Could also be labeled as -1 if it's easier.
Thanks alot for the help. Much appreciated.
EDIT Clarification. User_id(1), 2013-10-05 has a tau value of 1 because they haven't logged back in when treating the current day as the 7th. e.g So if someone hasn't logged back in, their tau value keeps increasing. So since user_id=1 last logged in on the 5th, they currently have a tau value of 1, and that value will keep increasing by 1 for everyday they don't log back in. Thanks again-especially to a_horse_with_no_name and Linger for the quick responses and helping me clarify the question