Another MySQL question about averages. Remove outliers.
I have a number of observations that I can get from a MySQL database.
Let's assume the values I have are, ordered ascending:
3, 5, 5, 6, 6, 6, 8, 9, 15.
Just calculating the AVG results in 63/9 = 7.00
If I want to repeat that but leave out both the minimum and the maximum values, in this case both the 3 and the 15, giving the following list:
5, 5, 6, 6, 6, 8, 9
then the average is only 45/7 = 6.43 to gain more statistical accuracy, how do I need to modify my query?
Currently the query is like this:
$query_Recordset1 = 'SELECT COUNT(Graphics_card) AS Obs, Graphics_card, AVG(MPE_Off/MPE_On) AS Gain , AVG(MPE_On) AS Speed FROM `Personal_data` WHERE MPE_On >0 GROUP BY Graphics_card HAVING COUNT(Graphics_card) > 4 ORDER BY Speed ASC, Obs DESC, Gain DESC LIMIT 0, 20' ;
In this query the minimum number of observations is 5 for each distinct 'Graphics_card'. In the future I may change that to another figure and that is easy, just change the bold 4 to another figure but then, I may want to recalculate the adjusted average by leaving out the two bottom observations and the two top observations, so the range in the calculation would look like this:
5, 6, 6, 6, 8
and then the adjusted average is only 31/5 = 6.20
How do I need to adjust my query to achieve that?
Or, to put it another way, how can I first exclude the top X and bottom X observations from the query and only then calculate the AVG?
Here is the page I want to apply it to: http://ppbm5.com/MPE%20Charts.php
