您可以使用group_concat()
/substring_index()
方法执行此操作:
SELECT t.name,
substring_index(m.marks, ',', 1) as Mark1,
substring_index(substring_index(m.marks, ',', 2), ',', -1) as Mark2,
substring_index(substring_index(m.marks, ',', 3), ',', -1) as Mark3
m.top_marks
FROM table_name t cross join
(SELECT group_concat(marks order by marks desc) as marks
FROM table_name
) m
GROUP BY column_name DESC;
如果将它们放在一列中并用逗号分隔值就足够了:
SELECT t.name, substring_index(m.marks, ',', 3) as Marks3
FROM table_name t cross join
(SELECT group_concat(marks order by marks desc) as marks
FROM table_name
) m
GROUP BY column_name DESC;