Simple way to calculate median with MySQL
In MariaDB / MySQL: Steve Cohen points out, that after the first pass, @rownum will contain the total number of rows. This can be used to determine the median, so no second pass or join is needed. Also AVG(dd.val) and dd.row_number IN(…) is used to correctly produce a median when there are an even number of records. Reasoning: Finally, MariaDB 10.3.3+ … Read more