My SQL Tags

1

Please login or register to vote for this query.

(click on this box to dismiss)

Physical Fitness Meta

Q&A about the site for physical fitness professionals, athletes, trainers, and those providing health-related needs

SELECT TagName, Posts, Score, Rank = RowNumber
FROM ( SELECT u.Id, 
              u.DisplayName, 
              t.TagName, 
              Posts = COUNT(*), 
              Score = SUM(a.Score),
              RowNumber = RANK() OVER(PARTITION BY t.Id ORDER BY SUM(a.Score) DESC)
        FROM Posts q
            INNER JOIN Posts a
              ON a.ParentId = q.Id
            INNER JOIN PostTags pt
              ON pt.PostId = q.Id
            INNER JOIN Tags t
              ON t.Id = pt.TagId
            INNER JOIN Users u
              ON u.Id = a.OwnerUserId
        WHERE q.PostTypeId = 1
        AND a.PostTypeId = 2
        AND t.TagName LIKE 'sql%'
        GROUP BY u.Id, u.DisplayName, t.TagName, t.Id
        HAVING SUM(a.Score) > 100) X
WHERE Id = 1048425
ORDER BY RowNumber;

Enter Parameters

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