Q&A for people who build and repair bicycles, people who train cycling, or commute on bicycles
WITH PostData AS (SELECT PostId, MAX(case VoteTypeId when 2 then 1 else null end) as Upvoted, MAX(case VoteTypeId when 3 then 1 else null end) as Downvoted FROM Votes GROUP BY PostId, VoteTypeId) SELECT * FROM PostData --SELECT -- COUNT(case VoteTypeId when 2 then 1 else null end) as [Posts with upvotes], -- COUNT(case VoteTypeId when 3 then 1 else null end) as [Posts with downvotes]