Distribution of Users Activity Per Hour

3

Please login or register to vote for this query.

(click on this box to dismiss)

Per hour distribution of posts, comments and edits of a user. Looks great as a graph.

Economics

Q&A for those who study, teach, research and apply economics and econometrics

-- Distribution of User Activity Per Hour
-- Per hour distribution of posts, comments and edits of a user.

--declare @UserId int = ##UserId##

select h.hours as [Hour], /*count(postsCounter) as [Posts],*/ count(questionsCounter) as [Questions], count(answersCounter) as [Answers], count(commentsCounter) as [Comments]/*, count(suggestedCounter) as [Suggested Edits], count(editsCounter) as [Edits], count(counter) as [Total Activity]*/
from
(
select datepart(hour, creationdate) as active, 1 as counter, 1 as postsCounter, NULL as questionsCounter, NULL as answersCounter, NULL as commentsCounter, NULL as editsCounter, NULL as suggestedCounter from posts
union all
select datepart(hour, creationdate) as active, NULL as counter, NULL as postsCounter, 1 as questionsCounter, NULL as answersCounter, NULL as commentsCounter, NULL as editsCounter, NULL as suggestedCounter from posts where PostTypeId = 1
union all
select datepart(hour, creationdate) as active, NULL as counter, NULL as postsCounter, NULL as questionsCounter, 1 as answersCounter, NULL as commentsCounter, NULL as editsCounter, NULL as suggestedCounter from posts where PostTypeId = 2
union all
select datepart(hour, creationdate) as active, 1 as counter, NULL as postsCounter, NULL as questionsCounter, NULL as answersCounter, 1 as commentsCounter, NULL as editsCounter, NULL as suggestedCounter from comments
union all
select datepart(hour, creationdate) as active, 1 as counter, NULL as postsCounter, NULL as questionsCounter, NULL as answersCounter, NULL as commentsCounter, NULL as editsCounter, 1 as suggestedCounter from suggestededits
union all
select datepart(hour, creationdate) as active, 1 as counter, NULL as postsCounter, NULL as questionsCounter, NULL as answersCounter, NULL as commentsCounter, 1 as editsCounter, NULL as suggestedCounter from posthistory
) 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

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results