SELECT TOP 5 Input.Id [User Link], Input.Id, u.Reputation...

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

SELECT TOP 5
  Input.Id [User Link],
  Input.Id,
  u.Reputation,
  SUM(Daily_Score)
FROM
  (
  SELECT
    u.Id,
    DATEADD(day, DATEDIFF(day, 0,v.CreationDate), 0) AS TimeStamp,
      CASE
        WHEN 
          SUM(CASE 
            WHEN v.VoteTypeId = 2 THEN 10
            WHEN v.VoteTypeId = 3 THEN -2 
            ELSE NULL
            END) > 200 THEN 200 
        ELSE 
          SUM(CASE 
            WHEN v.VoteTypeId = 2 THEN 10
            WHEN v.VoteTypeId = 3 THEN -2 
            ELSE NULL
            END)
        END
        AS Daily_Score

  FROM 
    Users u
  JOIN Posts p ON p.OwnerUserId = u.Id
  JOIN Votes v ON v.PostId = p.Id
  GROUP BY u.id, DATEDIFF(day, 0,v.CreationDate)
  ) AS Input
JOIN Users u ON u.Id = Input.Id
GROUP BY Input.Id, u.Reputation

Enter Parameters

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