MySQL | Group_CONCAT() Function | mysql pivot rows to columns string field | MySQL Pivot: rotating rows to columns | mysql group by string column

Mysql pivot rows to columns string field |
mysql group by string column

The GROUP_CONCAT() function in MySQL is 
used to concatenate data from multiple rows into one field.


CREATE table testcase(
subproperty varchar(50),
valuestr varchar(50));

INSERT INTO accountsreportdb.testcase(subproperty, valuestr) VALUES
('backup', 'sp'),
('os', 'win'),
('plat', 'LX'),
('model', 'vmware');

SELECT * FROM testcase;

SELECT GROUP_CONCAT(CASE WHEN subproperty='backup' THEN valuestr END) backup,
GROUP_CONCAT(CASE WHEN subproperty='os' THEN valuestr END) os,
GROUP_CONCAT(CASE WHEN subproperty='plat' THEN valuestr END) plat,
GROUP_CONCAT(CASE WHEN subproperty='model' THEN valuestr END) model from testcase;

RESULT:




Post a Comment

1 Comments