Avid answerers of the site, monthly history

1

Please login or register to vote for this query.

(click on this box to dismiss)

Physical Fitness Meta

Q&A about the site for physical fitness professionals, athletes, trainers, and those providing health-related needs

DECLARE @TsNow DATETIME;

SELECT @TsNow = DATEFROMPARTS(
  DATEPART(yyyy, MAX(CreationDate)),
  DATEPART(mm, MAX(CreationDate)),
  1)
FROM Posts;

WITH Raw AS (
  SELECT
    DATEFROMPARTS(
      DATEPART(yyyy, CreationDate),
      DATEPART(mm, CreationDate),
      1) AS Month,
    OwnerUserId AS UserId,
    CASE
      WHEN COUNT(*) > ##MaxAnswerPerMonth:int?5##
      THEN ##MaxAnswerPerMonth##
      ELSE COUNT(*)
    END AS AnswerCount
  FROM Posts
  WHERE
    PostTypeId = 2
    AND
    OwnerUserId > 0
    AND
    CreationDate < @TsNow
  GROUP BY
    DATEFROMPARTS(
      DATEPART(yyyy, CreationDate),
      DATEPART(mm, CreationDate),
      1),
    OwnerUserId
)
SELECT
  Month,
  CASE
    WHEN AnswerCount < ##MaxAnswerPerMonth##
    THEN CAST(AnswerCount AS VARCHAR(MAX))
    ELSE CAST(AnswerCount AS VARCHAR(MAX)) + ' or more'
  END AS AnswerCount,
  COUNT(*) AS UserCount
FROM Raw
GROUP BY Month, AnswerCount
ORDER BY Month DESC, AnswerCount

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results