Per hour distribution of posts, comments and edits of a user.
Q&A about the site for serious players and enthusiasts of poker
-- Distribution of User Activity Per Hour -- Per hour distribution of posts and comments of a user. declare @UserId int = ##UserId## select h.hours as [Hour], count(postsCounter) as PostsActivity, count(commentsCounter) as CommentsActivity, count(suggestedCounter) as SuggestedActivity, count(editsCounter) as EditsActivity, count(counter) as AmountOfActivity from ( select datepart(hour, creationdate) as active, 1 as counter, 1 as postsCounter, NULL as commentsCounter, NULL as editsCounter, NULL as suggestedCounter from posts where owneruserid = @UserId union all select datepart(hour, creationdate) as active, 1 as counter, NULL as postsCounter, 1 as commentsCounter, NULL as editsCounter, NULL as suggestedCounter from comments where userid = @UserId union all select datepart(hour, creationdate) as active, 1 as counter, NULL as postsCounter, NULL as commentsCounter, NULL as editsCounter, 1 as suggestedCounter from suggestededits where owneruserid = @UserId union all select datepart(hour, creationdate) as active, 1 as counter, NULL as postsCounter, NULL as commentsCounter, 1 as editsCounter, NULL as suggestedCounter from posthistory where userid = @UserId ) as a right join ( select distinct datepart(hour, CreationDate) as hours from posts ) as h on a.active = h.hours group by h.hours order by h.hours