Up & Down Votes

1

Please login or register to vote for this query.

(click on this box to dismiss)

Code Review

Q&A for peer programmer code reviews

with updown as(
  Select VoteTypes.Name As VoteType,
      PostTypes.Name As PostType,
      Votes.CreationDate, 
      Count(Votes.Id) As Tally
  From Votes 
  Inner Join VoteTypes
  On Votes.VoteTypeId = VoteTypes.Id
  Inner Join Posts
  On Votes.PostId = Posts.Id
  Inner Join PostTypes
  On Posts.PostTypeId = PostTypes.Id
  Where VoteTypes.Id In(2,3)
  And Posts.PostTypeId In(1,2)
  Group By VoteTypes.Name,
      PostTypes.Name,
      Votes.CreationDate
  --Order By Votes.CreationDate Desc
)

Select PostType, CreationDate, DownMod, UpMod
From updown
Pivot(Sum(TallY)
  For VoteType In(
      [DownMod],[UpMod]
    )  
  )as pivoted
Order by CreationDate Desc, PostType

Enter Parameters

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