I have a single table that houses student scores by their classes. For example, each class has 30 students, so there are 30 scores for each class. I'd like to do a simple report that averages, does a median, and a mode, for each data set per class. So, each class will have an average, a median, and a mode. I know that SQL Server does not have a built in function for median and mode, and I found sample SQLs for the median. However, the samples I found do not do any grouping, I found:
SELECT
(
(SELECT MAX(Value) FROM
(SELECT TOP 50 PERCENT Value FROM dbo.VOrders ORDER BY Value) AS H1)
+
(SELECT MIN(Value) FROM
(SELECT TOP 50 PERCENT Value FROM dbo.VOrders ORDER BY Value DESC) AS H2)
) / 2 AS Median
Is it possible to modify to add a group by so I get a median value per class?