参考:
http://blog.sina.com.cn/s/blog_72e6be570101w731.html
percentile(array,p)算法一般是:
将数组array从小到大排序,计算(n-1)*p的整数部分为i,小数部分为j,其中n为数组大小,则percentile的值是:(1-j)*array第i+1个数+j*array第i+2个数。
![](//img.blog.itpub.net/blog/attachment/201604/22/29254281_1461324182U5eu.png?x-oss-process=style/bb)
(10-1)*0.8=7.2
那么i=7,j=0.2
(1-0.2)*8+0.2*9=8.2
在Oracle里面是这样的.
![](//img.blog.itpub.net/blog/attachment/201604/22/29254281_1461324439Kwv4.png?x-oss-process=style/bb)
hive
![](//img.blog.itpub.net/blog/attachment/201604/22/29254281_146132455575zb.png?x-oss-process=style/bb)
hive explode 拆列
![](//img.blog.itpub.net/blog/attachment/201604/22/29254281_1461324828vROK.png?x-oss-process=style/bb)
http://blog.sina.com.cn/s/blog_72e6be570101w731.html
percentile(array,p)算法一般是:
将数组array从小到大排序,计算(n-1)*p的整数部分为i,小数部分为j,其中n为数组大小,则percentile的值是:(1-j)*array第i+1个数+j*array第i+2个数。
![](http://img.blog.itpub.net/blog/attachment/201604/22/29254281_1461324182U5eu.png?x-oss-process=style/bb)
(10-1)*0.8=7.2
那么i=7,j=0.2
(1-0.2)*8+0.2*9=8.2
在Oracle里面是这样的.
![](http://img.blog.itpub.net/blog/attachment/201604/22/29254281_1461324439Kwv4.png?x-oss-process=style/bb)
hive
![](http://img.blog.itpub.net/blog/attachment/201604/22/29254281_146132455575zb.png?x-oss-process=style/bb)
hive explode 拆列
![](http://img.blog.itpub.net/blog/attachment/201604/22/29254281_1461324828vROK.png?x-oss-process=style/bb)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29254281/viewspace-2086291/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29254281/viewspace-2086291/