I\'m trying to get mean, median, mode and range for a set of values in a table. I was able to get the average but median, range and mode I\'m getting a wrong one.
Below
I imagine that you may rather want to do something like this:
select dbo.Median(DataValues_AttributeValue)
from ...
There is no slick way to get the median or mode in a manner similar to using the native aggregates such as avg, max, min, max, etc. However, you may want to try a .NET CLR aggregate implementation where you implement the median and mode in, for example, C# if you want something elegant, e.g. like the above code snippet.
This is what I've done in the past.