Number of posts per year scoring more or less then a threshold

1

Please login or register to vote for this query.

(click on this box to dismiss)

Input: threshold; post type.

Linguistics Meta

Q&A about the site for professional linguists and others with an interest in linguistic research and theory

Declare @ThresholdScore int = ##ThresholdScore##;
Declare @PostTypeId int = ##PostTypeId##;

WITH sqx_cte (q_year, more_less, q_count)
AS (
  SELECT
      YEAR(p.CreationDate) AS q_year
    , CASE WHEN p.Score >= @ThresholdScore THEN 'M' ELSE 'L' END more_less
    , COUNT(1) AS q_count
  FROM
      Posts p
  WHERE
      p.PostTypeId = @PostTypeId
  GROUP BY
      YEAR(p.CreationDate)
    , CASE WHEN p.Score >= @ThresholdScore THEN 'M' ELSE 'L' END
)
SELECT
    *
FROM
    sqx_cte
ORDER BY
    q_year
  , more_less

Enter Parameters

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