MySQL Forums
Forum List  »  Newbie

Transform rows to columns without NULL values
Posted by: Andrew Forest
Date: July 23, 2018 12:58PM

I would like to transform the first table, which is a result of a query, into the second table. At the first table, every value from the Y column has a value from the X, which can be the same. In the second table, I would like to reach that every X value will be a column with its own data from the Y column value. Could anyone send me a little note how to do that? Thank you.

Table First Table Second
---------- ------------------
| X | Y | | A | B | C | D |
---------- ------------------
| A | 1 | | 1 | 2 | 6 | 10 |
| B | 2 | | 1 | 3 | 7 | 11 |
| B | 3 | ==> | 1 | 4 | 8 | 12 |
| B | 4 | | 1 | 5 | 9 | 13 |
| B | 5 |
| C | 6 |
| C | 7 |
| C | 8 |
| C | 9 |
| D | 10 |
| D | 11 |
| D | 12 |
| D | 13 |
----------

Options: ReplyQuote


Subject
Written By
Posted
Transform rows to columns without NULL values
July 23, 2018 12:58PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.