group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])
表结构与数据如上
如果需要根据product_id分组并且把option_ids拼接起来,可以使用group_concat来实现
SELECT product_id,GROUP_CONCAT(option_ids) as option_ids_c FROM product_attribute_option GROUP BY product_id
排序
SELECT product_id,GROUP_CONCAT(option_ids ORDER BY option_ids DESC) as option_ids_c FROM product_attribute_option GROUP BY product_id
最后可以设置分隔符
SELECT product_id,GROUP_CONCAT(option_ids ORDER BY option_ids DESC SEPARATOR ';') as option_ids_c FROM product_attribute_option GROUP BY product_id