MySQL函数GROUP_CONCAT |
| 发布时间: 2012/7/26 16:54:20 |
|
关于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; 本文出自:亿恩科技【www.enkj.com】 |
京公网安备41019702002023号