This is the MYSQL table schema :
+---------------+---------------------+
| username | last_activity_time |
+---------------+---------------------+
| raphael | 2011-11-28 23:16:34 |
| donatello | 2011-11-28 23:17:36 |
| michaelengelo | 2011-11-29 10:08:28 |
| raphael | 2011-11-29 11:11:33 |
| leonardo | 2011-11-29 11:12:30 |
+---------------+---------------------+
A NEW record with username and last_activity_time is inserted for each activity.
Query requirement :
Select all users who did some activity DAILY between two dates say 2011-11-20 and 2011-11-30 ( both included )
“IN” query does not seem to be an option as it works for any value in the IN array, not ALL.
This query counts the number of different days for each username. And then retain only those for which this number is equal to the number of days between the two dates.
The expression “DATE_ADD( @date2, INTERVAL 1 DAY)” represents the date just after @date2. It it used rather than @date2 because “last_activity_time” contains date and also time.