I am currently trying to replicate the query behind the top users page for a certain tag, specifically the "All time" list, in this query on data.stackexchange.
The query is as below
DECLARE @tagName nvarchar(35) = '##tagName##'
SELECT TOP 50
TagName,
COUNT(*) AS UpVotes,
Users.DisplayName as UserName,
number = ROW_NUMBER() OVER (ORDER BY TagName)
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
INNER JOIN Users ON Posts.OwnerUserId = Users.Id
WHERE
Tags.TagName = @tagName
AND Posts.CommunityOwnedDate IS NULL
GROUP BY TagName, DisplayName
ORDER BY UpVotes DESC
However, comparing against real lists, it returns higher values per user.
As an example, on the maven tag, the first All time top user is currently khmarbaise with a score of 2,253, while the query above fetches 2323.
I used as reference similar queries like:
Question: how to get the query aligned with the official All time list?