my_percentileをCodeReposに入れてみた
Excelの関数PercentileをJavaScriptで
をベースにして、MySQLの拡張関数でmy_percentileを作成して、CodeReposに入れてみた。
lang/c/misc/my_percentile
使った結果は大体こんな感じ。
mysql> select * from a;
+------+
| n |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
+------+
10 rows in set (0.00 sec)
mysql> select percentile(n,.2) from a;
+------------------+
| percentile(n,.2) |
+------------------+
| 2.80000000000000 |
+------------------+
1 row in set (0.00 sec)