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.
In SQL 2012 or later, it's often easier to use the percentile_cont function to calculate the median. It looks like the rest of your question has already been addressed, but I thought you'd want to know about this option as well.