mysql将查询结果用逗号分隔开来

使用group_concat函数来实现功能

This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values.
--Mysql官方文档

mysql> SELECT student_name,
         GROUP_CONCAT(test_score)
       FROM student
       GROUP BY student_name;

一定要加上group by条件,否则不规范

猜你喜欢

转载自www.cnblogs.com/mrnx2004/p/11136520.html