计数和排序

时间:2014-12-05 04:13:02

标签: sql ms-access count sql-order-by

我有一个名为MaintenanceRequests的表,它列出了Building#,Letter,ReqeustDate,Description,Resolution,CompletedDate和MaterialsUsed

我希望能够计算每栋楼的维护请求数。因此,如果1A有10个请求,1B有3个,则构建1总共有13个请求。然后我想展示前三名。

我拥有的是:

SELECT TOP 3 Building, Count(Letter) AS NumberofRequests
FROM MaintenanceRequests
GROUP BY Building
ORDER BY NumberofRequests DESC;

然而,当我去运行查询时,它会要求我提供NumberofRequests的参数。

我该如何解决这个问题?

由于

1 个答案:

答案 0 :(得分:0)

直接按汇总排序,而不是按别名

排序
SELECT TOP 3 Building, Count(Letter) AS NumberofRequests
FROM MaintenanceRequests
GROUP BY Building
ORDER BY Count(Letter) DESC;