Interesting zero-scored answers

0

Please login or register to vote for this query.

(click on this box to dismiss)

Code Review

Q&A for peer programmer code reviews

-- copied from http://data.stackexchange.com/code%20review%20stack%20exchange/query/4038/find-interesting-unanswered-questions

DECLARE @UserId int = ##UserId##

create table #tags (TagId int, [Count] int)

insert #tags 
SELECT TOP 20 
    TagId,
    COUNT(*) AS UpVotes 
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 = 2
WHERE 
    Posts.OwnerUserId = @UserId
GROUP BY TagId
ORDER BY UpVotes DESC

-- get recent answers with a score of zero, joined to the tags which you find interesting

select distinct top 500
p.id as [Post Link],
p.lastactivitydate,
( 
    		SELECT	tagname + ','
    		FROM	tags INNER JOIN	
    				PostTags pt  ON tags.id = pt.TagId
   		WHERE	pt.PostId = q.Id
    		FOR XML PATH('')
    	) AS tagnames
from posts p
inner join posts q on p.parentid = q.id
join PostTags pt on pt.PostId = q.Id
join #tags t on t.TagId = pt.TagId
where p.posttypeid = 2 and p.score = 0
order by p.lastactivitydate desc

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results