Top 5 Tags (with overall posts) and top 5 posts within each (by score)

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

DECLARE @n_tags int;

SET @n_tags = 5;

SELECT
  PostTags.PostId, 
  PostTags.TagId, 
  n = ROW_NUMBER() OVER (
    PARTITION BY 
      PostTags.TagId
    ORDER BY 
      Posts.Score DESC
  )
FROM 
  PostTags
LEFT JOIN
  Posts
ON 
  PostTAgs.PostId = Posts.Id
WHERE
  PostTags.TagId IN (
    SELECT 
      TOP (@n_tags) Tags.Id
    FROM 
      Tags
    ORDER BY 
      Tags.Count DESC);

Enter Parameters

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