Q&A about the site for expert genealogists and people interested in genealogy or family history
select PostId, SUM(CASE WHEN a.VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes, SUM(CASE WHEN a.VoteTypeId = 3 THEN 1 ELSE 0 END) AS DownVotes FROM votes a INNER JOIN posts b ON a.PostId = b.Id AND b.PostTypeId IN (1,2) WHERE VoteTypeId IN (2,3) group by PostId