我有學生和評估表。有必要返回所有評級的重複次數,但不包括MIN和MAX重複次數。SQL有聚合函數嗎?
當我'運行過程中出現此查詢:
SELECT
[Grade],
COUNT([Grade]) AS [Number of repetitions]
FROM [Test].[dbo].[Evaluation]
GROUP BY Grade
我有這樣的結果,它是好的,但如何顯示此查詢withuout重複MIN和MAX數(在這種情況下,6 - 120 10 - 4)
Grade Number of repetitions
6 120
7 35
8 93
9 25
10 4
我試過這樣做,但它不起作用。這是SQL中的消息:「不能對包含聚集或子查詢的表達式執行聚合函數」
SELECT
[Grade],
COUNT([Grade]) AS [Number of repetitions]
FROM [Test].[dbo].[Evaluation]
GROUP BY Grade
HAVING COUNT([Grade) > (SELECT MIN(COUNT([Grade])) FROM [Test][dbo].[Evaluation] GROUP BY Grade)
AND
HAVING COUNT([Grade) < (SELECT MAX(COUNT([Grade])) FROM [Test][dbo].[Evaluation] GROUP BY Grade)
非常感謝。
您使用的數據庫是? –
MS SQL Server 2012 – enzodev