mysql函数GROUP_CONCAT

关于mysql函数GROUP_CONCAT

GROUP_CONCAT()是MySQL数据库提供的一个函数,通常跟GROUP BY一起用,具体可参考MySQL官方文挡:http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat 。

 

GROUP_CONCAT( [ DISTINCT ] expr [ ,expr ... ] [ ORDER BY { unsigned_integer | col_name | expr} [ ASC | DESC ] [ ,col_name ...] ] [ SEPARATOR str_val] )

 

SELECT student_id, GROUP_CONCAT( courses_id) AS courses FROM student_courses WHERE student_id=2 GROUP BY student_id;

 

"SELECT student_id, GROUP_CONCAT(courses_id) AS courses FROM student_courses WHERE student_id=2 GROUP BY student_id"

 

SELECT student_id, GROUP_CONCAT( courses_id SEPARATOR '|||' )  AS courses FROM student_courses WHERE student_id=2 GROUP BY  student_id;

 

SELECT student_id, GROUP_CONCAT( courses_id ORDER BY courses_id DESC) AS courses FROM student_courses WHERE student_id=2 GROUP BY student_id;

 

 

你可能感兴趣的:(group_concat)