Select nth percentile from MySQL

后端 未结 3 394
情话喂你
情话喂你 2021-01-19 18:43

I have a simple table of data, and I\'d like to select the row that\'s at about the 40th percentile from the query.

I can do this right now by first querying to find

3条回答
  •  隐瞒了意图╮
    2021-01-19 19:15

    This will give you approximately the 40th percentile, it returns the row where 40% of rows are less than it. It sorts rows by how far they are from the 40th percentile, since no row may fall exactly on the 40th percentile.

    SELECT m1.field, m1.otherfield, count(m2.field) 
      FROM mydata m1 INNER JOIN mydata m2 ON m2.field

提交回复
热议问题