1.函数(GROUP_CONCAT):GROUP_CONCAT()是MySQL数据库提供的一个函数,通常跟GROUP BY一起用,具体可参考MySQL官方文
语法: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=2GROUP BY student_id;
SELECT student_id, GROUP_CONCAT(courses_id SEPARATOR '|||') AS courses FROM student_courses WHEREstudent_id=2 GROUP BY student_id;
SELECT student_id, GROUP_CONCAT(courses_id ORDER BY courses_id DESC) AS courses FROMstudent_courses WHERE student_id=2 GROUP BY student_id;