我有一个查询,希望通过以下方式从SEDE中获取最受欢迎的问题
SELECT TOP 10
'https://stackoverflow.com/questions/' + CONVERT(VARCHAR, Posts.Id) as url,
(ViewCount / (SELECT - DATEDIFF(DAY, GETDATE(), CreationDate))) AS ave_views_per_day,
Body as QUESTION,
Posts.Id,
Title
FROM
Posts
LEFT JOIN
PostTags ON Posts.Id = PostTags.PostId
LEFT JOIN
Tags ON PostTags.TagId = Tags.Id
WHERE
TagName IN ('##tag##')
AND ViewCount > 10000
ORDER BY
ave_views_per_day DESC
我有一个额外的查询来获得给定问题 ID 的最高得分答案:
SELECT
'https://stackoverflow.com/questions/' + CONVERT(VARCHAR, Id) as url, HighestScoringAnswer
FROM
(SELECT TOP 1
Id, Body AS HighestScoringAnswer,
DENSE_RANK() OVER (ORDER BY Score DESC) Rank
FROM
(SELECT p.Id, p.ParentId, p.Body, p.Score
FROM Posts p
WHERE p.ParentId = ##QuestionId##) x
ORDER BY
Rank ASC) x
如何组合这些查询,以便##QuestionId##
第二个查询的来源来自Posts.Id
第一个查询,并将结果HighestScoringAnswer
列添加到第一个查询的结果中?我尝试使用该Union
操作,但无法弄清楚如何将 Id 从一个查询“传递”到另一个查询。