Get Top Tags

1

Please login or register to vote for this query.

(click on this box to dismiss)

Gets the tags for which the user is in the top 1%, top 5%, and top 10%.

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

WITH tagAndUserStats AS (
  SELECT
    t.TagName,
    p.OwnerUserId AS userId,
    SUM(p.Score) AS tagScore,
    COUNT(p.Id) As postCount
  FROM Posts p
  INNER JOIN PostTags pt ON pt.PostId = COALESCE(p.ParentId, p.Id)
  INNER JOIN Tags t ON pt.TagId = t.Id
  WHERE p.OwnerUserId >= 1
  AND p.PostTypeId IN (1, 2)
  GROUP BY t.TagName, p.OwnerUserId
)
SELECT
  u.Id AS [User Link],
  u.Reputation,
  (
    SELECT TOP 1 tu.TagName
    FROM tagAndUserStats tu
    WHERE tu.userId = u.Id
    ORDER BY tu.tagScore DESC
  ) AS [Top Tag by Score],
  (
    SELECT TOP 1 tu.TagName
    FROM tagAndUserStats tu
    WHERE tu.userId = u.Id
    ORDER BY tu.postCount DESC
  ) AS [Top Tag by Posts]
FROM Users u
WHERE u.Id = ##UserId##

Enter Parameters

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