Top users of [tag] with positively received and non-closed posts

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

declare @tag nvarchar(35) = ##tag:string##;
declare @question tinyint = 1;
declare @answer tinyint = 2;

select
  Users.Id as [User Link],
  sum(P.Score) as [Total Score]
from
  Users
  left join Posts as P on P.OwnerUserId = Users.Id
where
  P.Tags like '%<' + @tag + '>%' 
  or 
  (
    P.PostTypeId = @answer 
    and exists (
      select * 
      from Posts as Parent
      where
      Parent.PostTypeId = @question
      and Parent.Id = P.ParentId
      and Parent.Tags like '%<' + @tag + '>%' 
      and Parent.Score >= 0
      and Parent.ClosedDate is null
    )
  )
  and P.Score >= 0
  and P.ClosedDate is null
group by
  Users.Id
order by
  [Total Score]
desc

Enter Parameters

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