Distribution of User Activity Per Hour

9

Please login or register to vote for this query.

(click on this box to dismiss)

Per hour distribution of posts and comments of a user.

Japanese Language Meta

Q&A about the site for students, teachers, and linguists wanting to discuss the finer points of the Japanese language

-- 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(counter) as AmountOfActivity
from
(
select datepart(hour, creationdate) as active, 1 as counter from posts where owneruserid = @UserId
union all
select datepart(hour, creationdate) as active, 1 as counter from comments 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

Enter Parameters

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