如何为十个最常用的标签(在SEDE中)提出十个最受欢迎的问题?

问题描述 投票:-1回答:1

Stack Exchange Data Explorer(SEDE)中,我试图获得十个最常用的问题,用于十个最常用的标签(即JavaScript,HTML,...)。

我看到如何获得最常用的标签:

select Id, TagName, Count
from Tags t
order by count desc

现在对于每个标签,我想获得前十大问题。我想我需要某种加入。问题是在Posts表中,Tags是一个数组。

tsql sql-server-2017 dataexplorer
1个回答
0
投票

请参阅the SEDE schema。使用PostTags表将标签链接到问题。

然后你可以使用ROW_NUMBER()对每个标签的前10个问题进行排名。

这是一种方式(See it live in SEDE):

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
© www.soinside.com 2019 - 2024. All rights reserved.