Top 10 questions for each of top ten tags

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

WITH topTags AS (
    SELECT TOP 10
                t.Id,
                t.TagName,
                t.Count,
                tagRank = ROW_NUMBER() OVER (ORDER BY t.Count DESC)
    FROM        Tags t
    ORDER BY    t.Count DESC
)
SELECT
        qbt.TagName     AS [Tag],
        --qbt.tagRank     AS [Tag Rank],
        qbt.Count       AS [Q's for Tag],
        qbt.Score       AS [Qst Score],
        qbt.Id          AS [Post Link],
        qbt.qstRow      AS [Rank in tag]
FROM (
    SELECT
                tt.TagName,
                --tt.tagRank,
                tt.Count,
                q.Score,
                q.Id,
                qstRow = ROW_NUMBER() OVER (PARTITION BY tt.Id ORDER BY tt.Id, q.Score DESC)
    FROM        topTags     tt
    LEFT JOIN   PostTags    pt  ON  pt.TagId = tt.Id
    LEFT JOIN   Posts       q   ON  q.ID = pt.PostId
) qbt
WHERE       qbt.qstRow <= 10
ORDER BY    qbt.Count DESC,
            qbt.Score DESC

Enter Parameters

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