如何使用 Stack Exchange Data Explorer 查找每个用户的热门标签?
How to use the Stack Exchange Data Explorer to find every user's top tags?
我在 the Stack Exchange Data Explorer 中使用此查询:
select id, reputation
from users
where reputation >300000
我应该向此查询添加什么,以便有一个带有用户 "best" 标记的附加列?
这是用户得分最高的标签and/or用户发帖(问题、回答)最多的标签。
例如,在我的用户页面中,在顶部标签中,我可以看到 r.
这是使用 Common Table Expressions (CTE's) and Correlated Subqueries 的一种方法。
在 SEDE 中查看:data.stackexchange.com/Whosebug/query/815284/...
WITH tagAndUserStats AS (
SELECT
t.tagname,
p.owneruserid AS userid,
SUM (p.score) AS tagScore,
COUNT (p.id) AS postCount
FROM posts p
INNER JOIN posttags pt ON pt.postid = COALESCE (p.parentid, p.id)
INNER JOIN tags t ON pt.tagid = t.id
WHERE p.owneruserid >= 1
AND p.posttypeid IN (1, 2)
GROUP BY t.tagname,
p.owneruserid
)
SELECT
u.id as [User Link],
u.Reputation,
( SELECT TOP 1 tu.tagname
FROM tagAndUserStats tu
WHERE tu.userid = u.id
ORDER BY tu.tagScore DESC
) AS [Top Tag by Score],
( SELECT TOP 1 tu.tagname
FROM tagAndUserStats tu
WHERE tu.userid = u.id
ORDER BY tu.postCount DESC
) AS [Top Tag by Posts]
FROM users u
WHERE u.reputation > 300000
ORDER BY u.reputation DESC
returns 结果如下:
User Link Reputation Top Tag by Score Top Tag by Posts
Jon Skeet 1010838 c# c#
BalusC 784437 java jsf
Darin Dimitrov 783553 c# c#
VonC 753855 git git
备注:
- 引用the SEDE schema.
- 因为您同时指定了问题和答案,并且没有排除 community wiki 帖子,所以此查询的结果有时会偏离习惯值。
对于徽章和诸如此类的东西,question-posts 和 question-scores 不算数,只有答案才算。
我在 the Stack Exchange Data Explorer 中使用此查询:
select id, reputation
from users
where reputation >300000
我应该向此查询添加什么,以便有一个带有用户 "best" 标记的附加列?
这是用户得分最高的标签and/or用户发帖(问题、回答)最多的标签。
例如,在我的用户页面中,在顶部标签中,我可以看到 r.
这是使用 Common Table Expressions (CTE's) and Correlated Subqueries 的一种方法。
在 SEDE 中查看:data.stackexchange.com/Whosebug/query/815284/...
WITH tagAndUserStats AS (
SELECT
t.tagname,
p.owneruserid AS userid,
SUM (p.score) AS tagScore,
COUNT (p.id) AS postCount
FROM posts p
INNER JOIN posttags pt ON pt.postid = COALESCE (p.parentid, p.id)
INNER JOIN tags t ON pt.tagid = t.id
WHERE p.owneruserid >= 1
AND p.posttypeid IN (1, 2)
GROUP BY t.tagname,
p.owneruserid
)
SELECT
u.id as [User Link],
u.Reputation,
( SELECT TOP 1 tu.tagname
FROM tagAndUserStats tu
WHERE tu.userid = u.id
ORDER BY tu.tagScore DESC
) AS [Top Tag by Score],
( SELECT TOP 1 tu.tagname
FROM tagAndUserStats tu
WHERE tu.userid = u.id
ORDER BY tu.postCount DESC
) AS [Top Tag by Posts]
FROM users u
WHERE u.reputation > 300000
ORDER BY u.reputation DESC
returns 结果如下:
User Link Reputation Top Tag by Score Top Tag by Posts Jon Skeet 1010838 c# c# BalusC 784437 java jsf Darin Dimitrov 783553 c# c# VonC 753855 git git
备注:
- 引用the SEDE schema.
- 因为您同时指定了问题和答案,并且没有排除 community wiki 帖子,所以此查询的结果有时会偏离习惯值。
对于徽章和诸如此类的东西,question-posts 和 question-scores 不算数,只有答案才算。