select mind(concat(color,'=',qty) SEPARATOR '||') from tb group by wc
SELECT wc, CAST(GROUP_CONCAT(CONCAT(color,'=',qty) SEPARATOR '||') AS CHAR) FROM tt4 GROUP BY wc
select wc,GROUP_CONCAT(CONCAT(color,'=',qty) SEPARATOR '||') from 表名 group by wc
create table csdn_0510_1( id int not null auto_increment primary key, wc varchar(30), color varchar(30), qty int ); insert into csdn_0510_1(wc,color,qty) select 'aa','s1',12 union all select 'bb','s3',2 union all select 'bb','s7',3 union all select 'bb','s9',4 union all select 'cc','s22',6 union all select 'dd','s3',7 union all select 'dd','s4',1; select wc,group_concat(concat(color,'=',qty)SEPARATOR'||') from csdn_0510_1 group by wc
mysql> select id,wc,group_concat(concat(color,'=',qty) separator '||') color from a group by wc; +----+------+------------------+ | id | wc | color | +----+------+------------------+ | 1 | aa | s1=12 | | 2 | bb | s3=2||s7=3||s9=4 | | 5 | cc | s22=6 | | 6 | dd | s3=7||s4=1 | +----+------+------------------+
from tb
group by wc
CAST(GROUP_CONCAT(CONCAT(color,'=',qty) SEPARATOR '||') AS CHAR) FROM tt4 GROUP BY wc
from 表名
group by wc
create table csdn_0510_1(
id int not null auto_increment primary key,
wc varchar(30),
color varchar(30),
qty int
);
insert into csdn_0510_1(wc,color,qty)
select 'aa','s1',12 union all
select 'bb','s3',2 union all
select 'bb','s7',3 union all
select 'bb','s9',4 union all
select 'cc','s22',6 union all
select 'dd','s3',7 union all
select 'dd','s4',1;
select wc,group_concat(concat(color,'=',qty)SEPARATOR'||')
from csdn_0510_1
group by wc
+----+------+------------------+
| id | wc | color |
+----+------+------------------+
| 1 | aa | s1=12 |
| 2 | bb | s3=2||s7=3||s9=4 |
| 5 | cc | s22=6 |
| 6 | dd | s3=7||s4=1 |
+----+------+------------------+