How can I calculate the median of each year for each code. Below is the mysql table:
tbl_sales:
+-----+------+------+------+
| cod | cant | mont | year |
+-----+------+------+------+
| 432 | 1 | 10 | 2012 |
| 432 | 2 | 10 | 2012 |
| 432 | 4 | 10 | 2012 |
| 432 | 2 | 3 | 2012 |
| 432 | 3 | 2 | 2016 |
| 432 | 2 | 1 | 2016 |
| 432 | 8 | 8 | 2017 |
+-----+------+------+------+
Manual calculation of the median:
+------+---+---+---+---+---+---+---+---+---+----+----+----+-------+
| year | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | TOTAL |
+------+---+---+---+---+---+---+---+---+---+----+----+----+-------+
| 2012 | | | 2 | | | | | | | 7 | | | 9 |
| 2016 | 2 | 3 | | | | | | | | | | | 5 |
| 2017 | | | | | | | | 8 | | | | | 8 |
+------+---+---+---+---+---+---+---+---+---+----+----+----+-------+
MEDIAN (5,8,9) = 8
How can I display in sql this way: 432 => 8
Thank you!