I've an activity tracker table with activity_id
(Primary key, auto increment), user_id, api_function and date_added fields (please find the screenshot attached).
By using the below query I was able to count the number of entries per user in the last 28 days:
SELECT COUNT( DISTINCT date(date_Added) ) AS day_of_activity, user_id
FROM activity_tracker
WHERE date_added >= DATE( NOW() ) - INTERVAL 28 DAY
GROUP BY user_id
LIMIT 0 , 30
like:
days_of_activity user_id
34 1
1 3
13 9
2 10
1 11
8 12
I need to track the count of users who have:
more than 16 entries in the past 28 days
between 6 to 16 in the past 28 days,
1 to 6 in the past 28 days,
no entries in the past 30 days,
no entries in the past 90 days and
no entries in the past 180 days.
Is it possible to do this in single mysql query?
Please help me. Thanks in advance.