Question count by hour and day for a tag

1

Please login or register to vote for this query.

(click on this box to dismiss)

The number of questions for a given tag in the last year occuring on each day of the week and each hour of the day

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

declare @start datetime, @total float, @tag varchar(50) = '##Tag##'

select @start = dateadd(d, -364, max(CreationDate))
from posts

select @total = count(*)
from posts
where CreationDate > @start
and posttypeid = 1
and id in (
  select pt.postid
  from posttags pt
  join Tags t on pt.tagid = t.id
  where t.tagname like @tag
  )
  

select 
   datepart(hh, CreationDate) hour
  ,datename(dw, CreationDate) day
  ,count(*) posts
  ,convert(varchar(6), round((count(*) / @total) * 100, 2)) + '%' pct
from posts
where creationDate > @start
and posttypeid = 1
and id in (
  select pt.postid
  from posttags pt
  join Tags t on pt.tagid = t.id
  where t.tagname like @tag
  )
group by datepart(dw, CreationDate), datepart(hh, CreationDate), datename(dw, CreationDate)
order by datepart(dw, CreationDate), datepart(hh, CreationDate)

Enter Parameters

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