tag score for user and tag

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @userID int
SET @userID = ##userID:int##


select u.id as [User Link], t.TagName, count(*) as [Num Votes]
from Posts q
inner join Posts a on a.parentId = q.id
inner join users u on u.id = a.owneruserid
INNER JOIN PostTags pt ON q.id = pt.PostId
INNER JOIN Tags T ON pt.TagId = t.id and t.TagName = '##tagName##'
INNER JOIN votes v ON v.PostId = a.id and v.VoteTypeId = 2 -- up votes
where a.PostTypeID = 2  -- Answers only
and a.owneruserid = @userID
group by u.id, t.TagName
union
select u.id as [User Link], t.TagName, -(count(*)) as [Num Votes]
from Posts q
inner join Posts a on a.parentId = q.id
inner join users u on u.id = a.owneruserid
INNER JOIN PostTags pt ON q.id = pt.PostId
INNER JOIN Tags T ON pt.TagId = t.id and t.TagName = '##tagName##'
INNER JOIN votes v ON v.PostId = a.id and v.VoteTypeId = 3 -- down votes
where a.PostTypeID = 2  -- Answers only
and a.owneruserid = @userID
group by u.id, t.TagName

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results