mysql-udf
mysql-udf copied to clipboard
Median - when count is even, median need to be as AVG value
Hi,
thank you for UDF MEDIAN function. It works well with one issue.
From Wikipedia:
If n is odd then Median (M) = value of ((n + 1)/2)th item term.
If n is even then Median (M) = value of [((n)/2)th item term + ((n)/2 + 1)th item term ]/2
Issue is, when items count is even - for example, 2, or 4 items.
For example, for 2 items (5, 10), true median is 7.5, but MEDIAN function returns 5.
Could you implement this behavior?
Thank you very much.
Aaaa, it's already implemented in this fork :-)
https://github.com/TheDleo/mysql-udf/commit/b4c1add1bca1ecb05ba105f45b5bba0d78dfb997