MySQL Pivot Query (convert a table in a 2-dim matrix)