测试数据表
以product_id;分组,把name字段的值打印在一行,逗号分隔(默认)
SELECT id,GROUP_CONCAT(name) FROM test_brand GROUP BY product_id;
以id分组,把name字段的值打印在一行,分号分隔
SELECT id,GROUP_CONCAT(name SEPARATOR ';') FROM `test_brand` GROUP BY product_id;
测试数据表
以product_id;分组,把name字段的值打印在一行,逗号分隔(默认)
SELECT id,GROUP_CONCAT(name) FROM test_brand GROUP BY product_id;
以id分组,把name字段的值打印在一行,分号分隔
SELECT id,GROUP_CONCAT(name SEPARATOR ';') FROM `test_brand` GROUP BY product_id;
转载于:https://www.cnblogs.com/zelzzz/p/7496884.html