My answser scores in the top 40 tags

0

Please login or register to vote for this query.

(click on this box to dismiss)

Lifehacks

Q&A for people looking to bypass life's everyday problems with simple tricks

-- My answser scores in the top 40 tags

DECLARE @UserId int = ##UserId##

SELECT t4.TagName, topscores.ScoreSum
FROM Tags t4
JOIN (
    SELECT TOP 40 pt3.TagId, scores.ScoreSum
    FROM PostTags pt3
    LEFT JOIN (
        SELECT SUM(p2.Score) AS ScoreSum, pt.TagId AS TagId
        FROM Posts p
        JOIN PostTags pt ON pt.PostId = p.Id
        JOIN Posts p2 ON p2.ParentId = p.Id
        WHERE p2.OwnerUserId = @UserId
        GROUP BY pt.TagId
    ) AS scores ON scores.TagId = pt3.TagId
    GROUP BY pt3.TagId, scores.ScoreSum
    ORDER BY COUNT(pt3.TagId) DESC
) AS topscores ON topscores.TagId = t4.Id
ORDER BY topscores.ScoreSum DESC

Enter Parameters

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