upvotes and downvotes per post in first week by month

0

Please login or register to vote for this query.

(click on this box to dismiss)

Tridion

Q&A for Tridion developers and administrators

select 
  dateadd(m, datediff(m,0, Posts.CreationDate), 0) as month,
  cast(sum(case when votes.votetypeid = 2 then 1 else 0 end) as float) / Count(distinct Posts.Id) as upvotes_per_post,
    cast(sum(case when votes.votetypeid = 3 then 1 else 0 end) as float) / Count(distinct Posts.Id) as downvotes_per_post

from
  Votes
    left outer join
  Posts
    on
  Posts.Id = Votes.PostId
where
  (Votes.VoteTypeId = 2
    or
    Votes.VoteTypeId = 3)
  and datediff(dd,Posts.CreationDate,Votes.CreationDate) <= 7
  and dateadd(m, datediff(m,0, Posts.CreationDate), 0)
    < dateadd(m, datediff(m,0, getdate()), 0)
group by dateadd(m, datediff(m,0, Posts.CreationDate), 0)
order by dateadd(m, datediff(m,0, Posts.CreationDate), 0)

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results