Unfortunately MySQL
does not have a PIVOT
function which is basically for what I trying to do.
I need on the return set rows values as column name using the stored procedure below this link credits @Akina
MySQL pivot tables - rows to colums . Query
But I have an error using
CALL PIVOT('sourcetable', 'contents', 'sUn', 'contents')
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' ) ) parsed' at line 16 Time: 0,586s
This is the MySql table
+---------+----------+
| sUn | contents |
+---------+----------+
| Area NO | 1234567 |
| Zone S | 1234568 |
| Zone N | 1234560 |
| Zone I | 1234561 |
| Zone C | 1234562 |
| Zone G | 1234566 |
| Zone V | 1234564 |
| Zone B | 1234565 |
| Zone A | 1234569 |
| CR | 1234562 |
| ESA | 1234561 |
| EPI | 1234564 |
| SV | 1234563 |
| SA | 1234567 |
+---------+----------+
And this the to_columnslist
view
SELECT DISTINCT
concat( '`', `t_table`.`sUn`, '` VARCHAR(255) path \'$."', `t_table`.`sUn`, '"\'' ) AS `line`
FROM `t_table`;
+--------------------------------------------+
| line |
+--------------------------------------------+
| `Area NO` VARCHAR(255) path '$."Area NO"' |
| `Zone S` VARCHAR(255) path '$."Zone S"' |
| `Zone N` VARCHAR(255) path '$."Zone N"' |
| `Zone I` VARCHAR(255) path '$."Zone I"' |
| `Zone C` VARCHAR(255) path '$."Zone C"' |
| `Zone G` VARCHAR(255) path '$."Zone G"' |
| `Zone V` VARCHAR(255) path '$."Zone V"' |
| `Zone B` VARCHAR(255) path '$."Zone B"' |
| `Zone A` VARCHAR(255) path '$."Zone A"' |
| `CR` VARCHAR(255) path '$."CR"' |
| `ESA` VARCHAR(255) path '$."ESA"' |
| `EPI` VARCHAR(255) path '$."EPI"' |
| `SV` VARCHAR(255) path '$."SV"' |
| `SA` VARCHAR(255) path '$."SA"' |
+--------------------------------------------+
14 rows in set (0.11 sec)
Pls, help me to do it.