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:
1 Comments
ji273 timberlandcanada,sorel montreal,fjällräven bunda,filasapatilhas,fjallravengreece,fila boty,muck boots canada,gabor canada,hugo boss αρωμα bx946
ReplyDelete