Top N tags relative popularity history

3

Please login or register to vote for this query.

(click on this box to dismiss)

Shows the most popular tags in percent of all questions asked in the month

Emacs

Q&A for those using, extending or developing Emacs

WITH TopTags AS (
  SELECT TOP ##TopN:INT?10## Id, TagName
  FROM Tags
  ORDER BY Count DESC
),
PostTagMonth AS (
  SELECT
    DATEFROMPARTS(
      DATEPART(yyyy, CreationDate),
      DATEPART(mm, CreationDate),
    1) AS Month,
    TopTags.TagName
  FROM Posts, PostTags, TopTags
  WHERE
    TopTags.Id = PostTags.TagId
    AND
    Posts.Id = PostTags.PostId
),
PostTagMonthGrouped AS (
  SELECT Month, TagName, COUNT(*) AS N
  FROM PostTagMonth
  GROUP BY Month, TagName
),
AllPostMonth AS (
  SELECT
    DATEFROMPARTS(
      DATEPART(yyyy, CreationDate),
      DATEPART(mm, CreationDate),
    1) AS Month
  FROM Posts
),
AllPostMonthGrouped AS (
  SELECT Month, COUNT(*) AS N
  FROM AllPostMonth
  GROUP BY Month
)
SELECT
  AllPostMonthGrouped.Month,
  PostTagMonthGrouped.TagName,
  100.0 * PostTagMonthGrouped.N / AllPostMonthGrouped.N AS PctOfMonth
FROM AllPostMonthGrouped
LEFT JOIN PostTagMonthGrouped
  ON AllPostMonthGrouped.Month = PostTagMonthGrouped.Month
WHERE AllPostMonthGrouped.Month > ##Since:string?2010-01-01##
ORDER BY AllPostMonthGrouped.Month, TagName

Enter Parameters

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