我正在编写一个数据浏览器查询以找到得分最低的已接受答案,这部分工作正常:
SELECT TOP 25 a.Id as [Post Link],
a.Score as Score,
(SELECT COUNT(*)
FROM Votes
WHERE PostId = a.Id AND
VoteTypeId = 2) AS [Upvotes],
(SELECT COUNT(*)
FROM Votes
WHERE PostId = a.Id AND
VoteTypeId = 3) AS [Downvotes]
FROM Posts q INNER JOIN Posts a ON q.AcceptedAnswerId = a.Id
WHERE a.PostTypeId = 2
ORDER BY a.Score ASC
但是,当我试图计算发布答案的人的分数时,我无法让它接受我选择作为参数的[Upvotes]
和列,即:[Downvotes]
SELECT TOP 25 a.Id as [Post Link],
a.Score as Score,
(SELECT COUNT(*)
FROM Votes
WHERE PostId = a.Id AND
VoteTypeId = 2) AS [Upvotes],
(SELECT COUNT(*)
FROM Votes
WHERE PostId = a.Id AND
VoteTypeId = 3) AS [Downvotes],
(15 + (([Upvotes] * 10) - ([Downvotes] * 2))) AS [Answerer's Reputation]
FROM Posts q INNER JOIN Posts a ON q.AcceptedAnswerId = a.Id
WHERE a.PostTypeId = 2
ORDER BY a.Score ASC
我被告知[Upvotes]
并且[Downvotes]
不是有效的列名:
列名“Upvotes”无效。列名“Downvotes”无效。
我如何表明这[Upvotes]
与我刚刚声明的值相同:AS [Upvotes]
?或者这根本不可能,我必须作为存储过程手动完成?