Number of questions in Stack Overflow

0

Please login or register to vote for this query.

(click on this box to dismiss)

CiviCRM

Q&A for administrators and users of the CiviCRM Constituent Relationship Management software

-- Calculate number of questions per tag per year and total number of tags per year
WITH QuestionsPerTag AS (
    SELECT
        YEAR(p.CreationDate) AS Year,
        t.TagName,
        COUNT(*) AS QuestionsCount
    FROM
        Posts p
    JOIN
        PostTags pt ON p.Id = pt.PostId
    JOIN
        Tags t ON pt.TagId = t.Id
    WHERE
        p.PostTypeId = 1  -- Filter to include only questions 
        and
        t.TagName = 'telegram-bot'
    GROUP BY
        YEAR(p.CreationDate),
        t.TagName
),
TagsPerYear AS (
    SELECT
        YEAR(p.CreationDate) AS Year,
        COUNT(DISTINCT t.TagName) AS TotalTags
    FROM
        Posts p
    JOIN
        PostTags pt ON p.Id = pt.PostId
    JOIN
        Tags t ON pt.TagId = t.Id
    WHERE
        p.PostTypeId = 1  -- Filter to include only questions
    GROUP BY
        t.TagName, YEAR(p.CreationDate)
)
SELECT
    q.Year,
    q.TagName,
    q.QuestionsCount,
    t.TotalTags
FROM
    QuestionsPerTag q
JOIN
    TagsPerYear t ON q.Year = t.Year
GROUP BY
    q.Year,
    q.TagName,
    q.QuestionsCount,
    t.TotalTags

Enter Parameters

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