;with cte_rank as ( select row_number() over (order by re...

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

;with cte_rank as 
(
select row_number() over (order by reputation desc) pos
      , id
      , reputation
from users
)
, 
cte_200 as (
select row_number() over (order by reputation desc) pos
      , id
      , reputation
from users
where reputation > 200
)

select 'you' 
     , pos
     , id as [User Link]
     , reputation
     , (cast(pos as decimal) / (select count(*) from cte_rank)) * 100 [perc all]
     , (cast(pos as decimal) / (select count(*) from cte_200)) * 100 [perc league]
from cte_rank
where id = ##userid:int?156388##
union all 
select top 30
       'all'
     , pos
     , id 
     , reputation
     , (cast(pos as decimal) / (select count(*) from cte_rank)) * 100 
      , (cast(pos as decimal) / (select count(*) from cte_200)) * 100
from cte_rank
order by 1 desc, pos

Enter Parameters

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