原来GROUP_CONCAT中,是支持GROUP内排序的,自己好土。。
SELECT student_name,
GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ')
FROM student
GROUP BY student_name;[......]
MySQL中GROUP_CONCAT中排序
Leave a reply
原来GROUP_CONCAT中,是支持GROUP内排序的,自己好土。。
SELECT student_name,
GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ')
FROM student
GROUP BY student_name;[......]
转载自:http://www.geeklab.info/2012/11/mysql-how-to-get-top-n-rows-for-each-group/
We have the following table and data:
CREATE TEMPORARY TABLE girls(
name text,
haircolor text,
score INT
);
INSERT INTO girls VALUES ('M[......]