sql - How to see if a user was not active in all weeks/or active once every 2/4 weeks in a date range? -
suppose have table (id,userid,timestamp)
from data set after results this:
- 300 users active between oct 1 , nov 30 (query done)
- 10 users active less 1 day week (in other words, not active every week)
- of 10, 2 active once every 2 weeks (strict 2 weeks)
- of 10, 8 active once every 4 weeks (strict 4 weeks)
so questions are:
- how if user not active in weeks?
- how if user active once every 2 weeks?
you join list , try find entries match conditions. (without having checked it):
select l1.userid logs l1 inner join logs l2 on l2.timestamp > l1.timestamp , l2.timestamp < l1.timestamp + "1 week" , l1.userid = l2.userid
edit:
counting matched help:
select count(l1.userid) matches, l1.userid logs l1 inner join logs l2 on l1.userid = l2.userid , l2.timestampfake > l1.timestampfake , l2.timestampfake < l1.timestampfake + @interval l1.timestampfake > @start , l1.timestampfake < @end group l1.userid
Comments
Post a Comment