How can I transpose a row to a column in MySQL?
I've read some questions on this topic on StackOverflow, but I still have no idea how I can achieve the result that I want. I've also tried some code without success.
The following sample will hopefully make my desired result clear. I created a view named "summary_kcal" grouped by user-ID. It is composed as below:
+---------+------+------+------+------+------+------+------+
| userid | LU | MA | ME | GIO | VE | SA | DO |
+---------+------+------+------+------+------+------+------+
| 1 | 1000 | 2000 | 1000 | 1500 | 2000 | 1000 | 1500 |
+---------+------+------+------+------+------+------+------+
I want to convert it to:
+---------+---------+
| userid | 1 |
+---------+---------+
| LU | 1000 |
+---------+---------+
| MA | 2000 |
+---------+---------+
| ME | 1000 |
+---------+---------+
| GIO | 1500 |
+---------+---------+
| VE | 2000 |
+---------+---------+
| SA | 1000 |
+---------+---------+
| DO | 1500 |
+---------+---------+