Answer score quartiles as a function of length

0

Please login or register to vote for this query.

(click on this box to dismiss)

Plots quartiles of the answer score distribution as a function of answer length.

Stack Overflow

Q&A for professional and enthusiast programmers

WITH 
AllQuartiles(RoundedLength,PostScore,Quartile)
AS (
  SELECT TOP(##postsNo?100000##) 
  (ROUND(LEN(Body), -##logRound?3##) +0.5E##logRound?3##)
    AS RoundedLength,
  Score 
    AS PostScore,
  NTILE(4) OVER(PARTITION BY ROUND(LEN(Body), -##logRound?3##) ORDER BY Score) 
    AS Quartile
  FROM Posts
  WHERE 
    PostTypeId = 2 AND
    LEN(Body) <= ##maxLength?20000##
  ORDER BY
    ROUND(LEN(Body), -##logRound?3##),Score
)
SELECT 
  RoundedLength,
  MAX(CASE Quartile WHEN 1 THEN PostScore END) '1',
  MAX(CASE Quartile WHEN 2 THEN PostScore END) '2',
  MAX(CASE Quartile WHEN 3 THEN PostScore END) '3',
  MAX(CASE Quartile WHEN 4 THEN PostScore END) '4'
FROM 
  AllQuartiles
--WHERE
  --Quartile!=4
GROUP BY
  RoundedLength
ORDER BY
  RoundedLength

Enter Parameters

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