Rolling Daily Distinct Counts
We have a table with the following columns: SESSION_ID USER_ID CONNECT_TS -------------- --------------- --------------- 1 99 2013-01-01 2:23:33 2 101 2013-01-01 2:23:55 3 104 2013-01-01 2:24:41 4 101 2013-01-01 2:24:43 5 233 2013-01-01 2:25:01 We need to get a distinct count of users for each day and a count of "active users" which are defined as users that have used the application in the last 45 days. Here is what we have come up with, but I feel like there has to be a better way: select trunc(a.connect_ts) , count(distinct a.user_id) daily_users , count(distinct b.user_id) active_users