Displays up, down and accepted answers by tag
Q&A for those who study, teach, research and apply economics and econometrics
-- Tag Information -- Displays up, down and accepted answers by tag DECLARE @UserId int = ##UserId## Select p.TagName, p.UpMod, (IsNull(p.UpMod,0) * 10) as 'UpVoteValue', p.DownMod, -(IsNull(p.DownMod,0) * 2) as 'DownVoteValue', p.AcceptedByOriginator, (IsNull(p.AcceptedByOriginator,0) * 15) as 'AcceptedValue', (((IsNull(p.UpMod,0) * 10) - (IsNull(p.DownMod,0)* 2)) + (IsNull(p.AcceptedByOriginator,0) * 15)) as 'TotalReputation' From ( SELECT --TOP 20 TagName, VoteTypes.Name, COUNT(*) AS Votes FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId in (1,2,3) INNER JOIN VoteTypes on Votes.VoteTypeId = VoteTypes.Id WHERE Posts.OwnerUserId = @UserId GROUP BY TagName, VoteTypes.Name )q Pivot (sum(Votes) for Name in ([UpMod],[DownMod],[AcceptedByOriginator]) )p Order By 1,2