Sum of up and down votes for all posts of a given user.
Q&A for professional and enthusiast programmers
-- DECLARE @UserId INT = ##UserId##; SELECT TOP 15 u.id , u.DisplayName , COUNT(*) AS posts , COUNT(CASE WHEN pf.VoteTypeId = 2 THEN 1 ELSE NULL END) AS Anon_up , COUNT(CASE WHEN pf.VoteTypeId = 3 THEN 1 ELSE NULL END) AS Anon_down FROM Tags t JOIN PostTags pt ON pt.TagId = t.id JOIN PostFeedback pf ON pf.PostId = pt.PostId JOIN Posts p ON p.Id = pt.PostId JOIN Users u ON u.Id = p.OwnerUserId WHERE t.TagName = 'postgresql' GROUP BY u.id, u.DisplayName ORDER BY posts DESC;