mysql - SQL Query / find percentile based on rank -


i have created following tables ranks data set:

position  index indexl indexh amount rank 1          2.5    2      3     2000   1      1          2.5    2      3     3000   2 1          2.5    2      3     4000   3 1          2.5    2      3     5000   4 1          2.5    2      3     6000   5  2          1.5    1      2     2500   1      2          1.5    1      2     4500   2 2          1.5    1      2     6700   3 2          1.5    1      2     8900   4 2          1.5    1      2     9900   5 

now want find percentile based on ranks created using indices such following output :

position amount  1         3000+(4000-3000)*(2.5-2) 2         2500+(4500-2500)*(1.5-1) 

can me this. kinda new sql world.

thanks, monica

i think can want percentile_cont() aggregation function. looks want median:

select position,        percentile_cont(0.5) within group (order amount) median t group position; 

you can read more here.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -