Top users per tag

0

Please login or register to vote for this query.

(click on this box to dismiss)

Audio-Video Production Meta

Q&A about the site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation

-- Top users per tag

declare @user_id int = ##UserID##;
declare @limit int = ##Limit##;
declare @tag_id int = (select id from tags where tagname = '##TagName##');

--select rank() over (order by score desc) "Rank", * from (
select top (@limit)
  rank() over (order by sum(answers.score) desc) "Rank",
  users.id "User Link"
  ,sum(answers.score) as "Score"
  ,(case when users.id = @user_id then '<<<<' else '' end)
from users
join posts answers on (users.id = answers.owneruserid)
join posts parent on (answers.parentid = parent.id)
join posttags on (parent.id = posttags.postid)
where posttags.tagid = @tag_id
and answers.posttypeid = 2  -- answers only
group by users.id
order by sum(answers.score) desc
;

Enter Parameters

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