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

0

Please login or register to vote for this query.

(click on this box to dismiss)

Code Review

Q&A for peer programmer code reviews

/*
Best of Code Review 2016 - Best Newcomer (question) category
http://meta.codereview.stackexchange.com/questions/7129/best-of-code-review-2016-best-newcomer-question-category
*/
DECLARE @TargetYear INT = 2016;
DECLARE @Question INT = 1;
WITH FirstQuestions AS (
  SELECT MIN(p.Id) AS [PostId]
  FROM Posts AS p
  WHERE p.PostTypeId = @Question
  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