I have data in a MySQL database that looks something like this:
name |score
----------
alice|60
mary |55
...
A name can appear many times in the list, but can also appear just once. What I would like is to order the list based on the lower bound of a 95% confidence interval for the name. I tried the following:
SELECT name, count(*) as count_n, stddev_samp(score) as stdv, avg(score) as mean
FROM `my.table`
GROUP BY name
ORDER BY avg(score)-1.96*std(score)/sqrt(count(*)) desc
This produces an output that is ok. Ideally though, I would like to vary the value 1.96, since this should depend on the value of count_n for that name. In fact, it should be a value based on the t-distribution for count_n-1 degrees of freedom. Are there MySQL functions that can do this for me?
I have seen the following answer which looks good but doesn't vary the value as I wold like.