How to get mean ,median , mode and range in a single select query?

后端 未结 3 1262
死守一世寂寞
死守一世寂寞 2021-01-27 09:06

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

3条回答
  •  情话喂你
    2021-01-27 09:44

    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.

提交回复
热议问题