I have a table YEAR like this

I want to select this table, so that I can get

I wonder if it is possible to get table where every cell is independent (not as one row/field).
This is a real pain, but possible. The idea is to enumerate the values in each column and then "join" them together. The join is really a group by:
select max(`2014`) as `2014`,
max(`2015`) as `2015`,
. . .
from ((select (@rn2014 := @rn2014 + 1) as rn, `2014`,
NULL as `2015`, NULL as `2016`, NULL as `2017`
from year
where `2014` is not null
) union all
(select (@rn2015 := @rn2015 + 1) as rn, NULL, `2015`, NULL, NULL
from year
where `2015` is not null
) union all
. . .
) y
group by rn;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With