I am currently going through the activity log tables in the database to try and find out how many users make use of the application's batch processing functionality. As part of that, I'm trying to write a query to find outthe average number of activities each user has performed with each request, where a given request can have 1 (non-batch processing) or more (batch processing) records with an identical user ID and timestamp. Here's a simplified depiction of the table in question:
LogEntryNumber | UserID | ActivityTime |
1 | 1 | 2014-04-17 11:04:45.527 |
2 | 1 | 2014-04-17 11:04:45.527 |
3 | 1 | 2014-04-17 11:04:45.527 |
4 | 2 | 2014-04-30 07:52:39.243 |
5 | 2 | 2014-05-05 08:52:11.543 |
6 | 1 | 2014-05-13 08:41:09.173 |
7 | 3 | 2014-06-12 13:50:19.033 |
And here's the results I'd like to see:
UserID | AverageNumberOfActivitiesPerRequest |
1 | 2 |
2 | 1 |
3 | 1 |
What would be the SQL query for getting these results?