我想查询的数据中除了一个字段,其余字段的内容都一样,我怎么合并成一条呢?
例子:
原来:
姓名 性别 手机号码 爱好
张三 男 xxxxx 运动
张三 男 xxxxx 读书
张三 男 xxxxx 书法
想要:
姓名 性别 手机号码 爱好
张三 男 xxxxx 运动、读书、书法
SELECT group_concat(e_gender separator ',') from employee where e_name='SMISTH';
用group_concat就能连接起来,我上面举了一个例子,希望帮助到你
select 姓名,性别,手机号,group_concat(爱好) from aa group by 姓名,性别,手机号; 你完善一下试试
使用GROUP_ CONCAT,分组合并,
SELECT class_id ,class_name ,main_class_flag ,GROUP_CONCAT(stu_id SEPARATOR ',') as stuid from courses WHERE class_name = '计算机';
特此一试,有效。。赞