MySQL多行结果合并成一行,GROUP_CONCAT

测试数据表

测试数据表

**以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;

结果

# mysql   sql   编程思想  

评论

企鹅群:39438021

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×