Best of Code Review 2016 - Best Newcomer (answer) category

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

/*
Best of Code Review 2016 - Best Newcomer (answer) category
http://meta.codereview.stackexchange.com/questions/7128/best-of-code-review-2016-best-newcomer-answer-category
*/
DECLARE @TargetYear INT = 2016;
DECLARE @Answer INT = 2;
WITH FirstQuestions AS (
  SELECT MIN(p.Id) AS [PostId]
  FROM Posts AS p
  WHERE p.PostTypeId = @Answer
  GROUP BY p.OwnerUserId
)
SELECT
  fq.PostId AS [Post Link],
  p.OwnerUserId AS [User Link],
  p.Score,
  p.CreationDate
FROM 
  FirstQuestions AS fq
  JOIN Posts AS p
    ON fq.PostId = p.Id
WHERE
  DATEPART(YEAR, CreationDate) = @TargetYear
  AND p.ClosedDate IS NULL
GROUP BY
  fq.PostId,
  p.OwnerUserId,
  p.Score,
  p.CreationDate
ORDER BY 
  p.Score DESC,
  p.CreationDate ASC

Enter Parameters

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