HNQ algorithm

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

SELECT TOP 10
  Id AS [Post Link],
  ArbitraryHotnessPoints
FROM
(
  SELECT
    HNQValues.Id,
    ((IIF(AnswerCount > 10, 10, AnswerCount) * QScore) / 5 + AnswerScore) /
      POWER(IIF(QAgeHours + 1 < 6, 6, QAgeHours), 1.4) AS ArbitraryHotnessPoints
  FROM
  (
    SELECT
      Posts.Id,
      MAX(Posts.Score) AS QScore,
      DATEDIFF(SECOND, MAX(Posts.CreationDate), CURRENT_TIMESTAMP) / 3600.0 AS QAgeHours,
      COUNT(DISTINCT Answers.Id) AS [AnswerCount],
      SUM(AnswerScores.Score) / COUNT(DISTINCT Answers.Id) AS [AnswerScore]
    FROM Posts
    INNER JOIN Posts AS Answers ON Posts.Id = Answers.ParentId
    INNER JOIN (
      SELECT
        Score,
        ParentId
      FROM (
        SELECT Score, ParentId, Rank()
          over (PARTITION BY ParentId
                ORDER BY Score DESC ) AS Rank
        FROM Posts AS AScores
      ) Ranked WHERE Rank <= 3
    ) AS AnswerScores ON Posts.Id = AnswerScores.ParentId
    WHERE
      Posts.PostTypeId = 1 AND
      DATEDIFF(DAY, Posts.CreationDate, CURRENT_TIMESTAMP) <= 7
    GROUP BY Posts.Id
  ) AS HNQValues
) AS WithPoints
ORDER BY ArbitraryHotnessPoints DESC;

Enter Parameters

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