Reputation vs New Reputation Only for Last Month

0

Please login or register to vote for this query.

(click on this box to dismiss)

Software Engineering

Q&A for professionals, academics, and students working within the systems development life cycle

--Derived from http://data.stackexchange.com/stackoverflow/query/119271/rep-vs-new-rep-only
DECLARE @EndDateExcluded DateTime
DECLARE @StartDate DateTime
Set @EndDateExcluded= (SELECT top 1 cast(Posts.CreationDate as date) AS Date 
FROM Posts ORDER BY Posts.CreationDate desc);

Set  @StartDate=DATEADD(week ,-1, @EndDateExcluded);

--SELECT @StartDate,  @EndDateExcluded;


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 >= @StartDate
and v.creationDate < @EndDateExcluded
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 >= @StartDate
and v.creationDate < @EndDateExcluded
and p.creationDate >= @StartDate
and p.creationDate < @EndDateExcluded

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
,((RANK() OVER (Order by t.RepEarned Desc)) - (RANK() OVER (Order by n.RepEarned Desc))) Rank_Diff_New_vs_Trad
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 to meta site
loading Hold tight while we fetch your results