views:

40

answers:

2

How can we find percentile, skewness and kurtosis in MySQL? Is there any formula? I want to find the above three for a large number of data records.

Thank you, J

+1  A: 

I'd have to look up in the reference, but just in case you don't find the mathematical function you need, have a look at stored procedures. With this, you can define your own algorithms, if they're not present already.

Here's a nice tutorial, that you may want look into.

polemon
+2  A: 

Jillika,

Here is a simple query for skewness and excess kurtosis for data in the [sales] table from Microsoft's "pubs" sample database:

select sum((qty-mean)*square(qty-mean)
       /(N*sigma*square(sigma))) as skew,
       sum(square(square(qty-mean))
       /(N*square(square(sigma))))-3 as ExcessKurtosis
from pubs..sales,
(
  select
    avg(qty) as mean,
    stdev(qty) as sigma,
    count(qty) as N
  from pubs..sales
) S

(This and some other statistics queries are posted here: http://users.drew.edu/skass/sql/, and a query for Spearman's rho is here: http://stevekass.com/2008/03/29/spearmans-rho-for-sql-server/).

Also look at what Dejan Sarka has written on the topic here.

Steve Kass