I am trying to count the number of users who have had at least two sessions for 7 days or ten days for 30 days of all dates.
My data is as follows:
Date UserID SessionID 1/1/2013 Bob1234 1 2/1/2013 Bob1234 2 2/2/2013 Bob1234 3 2/3/2013 Cal5678 4
This will lead to the following table (show only selected dates)
Date CountActiveUsers 1/1/2013 1 1/15/2013 0 2/2/2013 1 2/3/2013 2
The actual data set has values ββfor all dates in a continuous range of data, and the result table should contain a record for each date.
SessionIDs are unique, and UserID always refers to the same person.
So far I have two queries that do something close. The first returns the number of sessions last week by the user:
SELECT Count( d.[SessionID] ) As SessionPastWeek ,m.[UserID] ,m.[Date] FROM [Cosmos].[dbo].[Sessions_tbl] as m Inner Join [Cosmos].[dbo].[Sessions_tbl] as d on m.[UserID2] = d.[UserID] AND
Another from the following link, which counts the number of active users on a given date, SQL query of active users
I am in SQL Server 2012
I'm having trouble merging the two.
Edit for clarification: for the query that I need, there most likely will not be any getdate () or the like, since I need to know how many users meet the βactiveβ criteria on January 1, today and all the dates between them.
Thanks for any help!
source share