简体   繁体   English

如何在MySQL中将行合并为具有相同列值的行

[英]How to combine rows into one with same column value in mysql

I have a table like this: 我有一张这样的桌子:

id  value  
1   a   
1   b   
2   c   
2   d   
2   e   

I want to combine rows with the same ids into one,here is what i want as result: 我想将具有相同ID的行合并为一个,这就是我想要的结果:

id  value  
1   a b 
2   c d e   

try this 尝试这个

select id,group_concat(value) as value from tb_name group by id;

if you want space instead ',' then try below query 如果要用空格代替“,”,请尝试以下查询

select id,replace(group_concat(value), ',' ,' ') as value from tb_name group by id;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 mysql 中在一列中合并多行? 当具有不同值的相同 ID 时 - In mysql combine multiple rows in one column? when having same ID with different value 如何将具有相同列值的mysql行分组为一行? - How to group mysql rows with same column value into one row? MySQL 查询一列值相同而另一列值不同的行 - MySQL query rows with same value in one column and different value in another PHP计算在一列中包含相同值的MYSQL行 - PHP counting MYSQL rows that contain the same value in one column 如何将以下更新查询合并为一个,用同一列的多个值更新多行,用其他值更新其余数据 - How to combine the below the update querys into one, Update multiple rows with multiple values for same column and the rest of data with other value 将多行合并为一行MySQL,并在同一查询中将值从一个字段拆分为两个 - Combine multiple rows into one row MySQL and split value from one field to two in same Query MYSQL:如何从具有相同列 id 值的多行中获取一行 - MYSQL: how to get one row from multiple rows with same column id value 如何在MySQL中合并具有相同值的行 - How to combine rows with same values in mysql MySQL将2行合并为一行 - MySQL Combine 2 rows into one mysql将具有相同列值的两行连接起来,并计算某些列值,并在一行中返回所有行 - mysql join two rows with same column value and calculate certain column values and return all rows in one row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM