2014-12-05 59 views
1

我有一個表叫MaintenanceRequests,它列出了大廈#,信,ReqeustDate,說明,分辨率,CompletedDate和MaterialsUsed計數和ORDER BY

我希望能夠來算每建築維修請求數。因此,如果1A有10個請求,1B有3個,則1號樓有13個請求。然後,我想只顯示前3

我有這樣的:

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

但是當我去運行它要求我爲NumberofRequests參數查詢。

我該如何解決這個問題?

感謝

回答

0

整理彙總,而不是直接通過它的別名

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

完美,謝謝! – 2014-12-05 06:20:56