How to transpose a table in mysql?

时间:2019-04-17 00:26:24

标签: mysql pivot transpose

i want to change the format of the table that i had. i've heard about the pivot statement but don't know how to apply it to my situation.

i thought about rearrange the table once i export it to csv file but it will take time and an extra step.

this is what i have so far

+------+------------+-----------+-------+
| name |    date    | breakfast | lunch |
+------+------------+-----------+-------+
| Mike | 21/02/2019 |         1 |     0 |
| Adam | 21/02/2019 |         1 |     0 |
| Liam | 13/05/2019 |         1 |     1 |
+------+------------+-----------+-------+

i would like to change the format to

+------------+-----------+-------+
|    days    | breakfast | lunch |
+------------+-----------+-------+
| 21/02/2019 |           |       |
| Mike       |         1 |     0 |
| Adam       |         1 |     0 |
| 13/05/2019 |           |       |
| Liam       |         1 |     1 |
+------------+-----------+-------+ 

it does not have to be exactly the same, i just want the export to show the name and meals based on date i tried to use group by but i got it wrong, please help

0 个答案:

没有答案