简体   繁体   English

在一行Mysql中合并多行

[英]Merge Multiple Rows in One Row Mysql

I have a sql table having multiple rows in which i want to get single row from same column value in my case SKU Column.I want to merge multiple rows from same sku value into one row having all values of attribute_id and attribute_value. 我有一个包含多行的sql表,在这种情况下,我希望从我的案例SKU Column中获取相同列值的单行。我想将来自相同sku值的多行合并为一行,其中包含attribute_id和attribute_value的所有值。

在此输入图像描述

If you are OK with having a comma-separated list of attribute IDs and values per each sku , then you could use GROUP_CONCAT : 如果您可以使用逗号分隔的每个sku的属性ID和值列表,那么您可以使用GROUP_CONCAT

SELECT sku,
       GROUP_CONCAT(attribute_id)    AS attribute_id,
       GROUP_CONCAT(attribute_value) AS attribute_value
FROM yourTable
GROUP BY sku

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM