Minimalistic PIVOT examples for Votes

1

Please login or register to vote for this query.

(click on this box to dismiss)

Emacs

Q&A for those using, extending or developing Emacs

select *
from 
( 
  SELECT Id          -- aggregate
       , VoteTypeId  -- columns 
   FROM Votes
) src
PIVOT 
( 
  count(Id) -- what we aggregate on 
  FOR VoteTypeId  in ([1], [2], [3]) -- accept, upmod, downmod
) pvt

select *
from 
( 
  SELECT Id          -- aggregate
       , postid      -- group by
       , VoteTypeId  -- columns 
   FROM Votes
) src
PIVOT 
( 
  count(Id) -- what we aggregate on 
  FOR VoteTypeId  in ([1], [2], [3]) -- accept, upmod, downmod
) pvt
order by [2] desc

Enter Parameters

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