Simple way to calculate median with MySQL

后端 未结 30 1119
北荒
北荒 2020-11-22 04:20

What\'s the simplest (and hopefully not too slow) way to calculate the median with MySQL? I\'ve used AVG(x) for finding the mean, but I\'m having a hard time fi

30条回答
  •  情歌与酒
    2020-11-22 04:42

    Knowing exact row count you can use this query:

    SELECT  AS VAL FROM  ORDER BY VAL LIMIT 1 OFFSET 
    
    
    

    Where = ceiling( / 2.0) - 1

    提交回复
    热议问题