Rep vs New Rep Only

2

Please login or register to vote for this query.

(click on this box to dismiss)

Ask Ubuntu

Q&A for Ubuntu users and developers

WITH  TOP_Traditional AS (
SELECT top 1000
    OwnerUserId,  
    SUM(Case WHEN v.VoteTypeID = 1 THEN 15
             WHEN v.VoteTypeID = 1 AND p.PostTypeID = 1 THEN  5
             WHEN v.VoteTypeID = 2 AND p.PostTypeID = 2 THEN  10
             WHEN v.VoteTypeID = 3 THEN  -2 END)  as RepEarned
    
FROM 
posts p
INNER JOIN Votes v
ON v.PostId = p.Id
WHERE OwnerUserId is not null
and v.creationDate >= '2012-04-01'
and v.creationDate < '2012-05-01'
GROUP BY 
  OwnerUserId
ORDER BY 
RepEarned DESC),
 TOP_NEWOnly AS (
SELECT top 1000
    OwnerUserId,  
    SUM(Case WHEN v.VoteTypeID = 1 THEN 15
             WHEN v.VoteTypeID = 1 AND p.PostTypeID = 1 THEN  5
             WHEN v.VoteTypeID = 2 AND p.PostTypeID = 2 THEN  10
             WHEN v.VoteTypeID = 3 THEN  -2 END)  as RepEarned
FROM 
posts p
INNER JOIN Votes v
ON v.PostId = p.Id
WHERE OwnerUserId is not null


and v.creationDate >= '2012-04-01'
and v.creationDate < '2012-05-01'
and p.creationDate >= '2012-04-01'
and p.creationDate < '2012-05-01'

GROUP BY 
  OwnerUserId
ORDER BY 
RepEarned DESC)
, final as(
SELECT 
COALESCE(t.OwnerUserId, n.OwnerUserId) [User Link],
RANK() OVER (Order by t.RepEarned Desc) T_rep_Rank,
RANK() OVER (Order by n.RepEarned Desc) N_Rep_rank,
t.RepEarned t_RepEarned,
n.RepEarned n_RepEarned
FROM
TOP_Traditional t
FULL OUTER JOIN TOP_NEWOnly n
ON t.OwnerUserID  = n.OwnerUserId
)
SELECT * FROM final 
ORDER BY n_rep_rank,t_rep_rank

Enter Parameters

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