Q&A about the site for students, teachers, and linguists wanting to discuss the finer points of the Italian language
with p as ( select id from Posts where PostTypeId = 2 ) ,a as ( select p.id, sum(case when v.votetypeid = 2 then 1 else 0 end) as upvotes, sum(case when v.votetypeid = 3 then 1 else 0 end) as downvotes from p join votes v on p.id = v.PostId where v.votetypeid in (2,3) --, p.ParentID = ##ParentQuestion:int?6095## group by p.id ) select upvotes, downvotes, count(id) from a group by upvotes, downvotes order by upvotes,downvotes