【MySQL】行转列

给定学生表如下
create table student
id int primary key,
name varchar(11),
course varchar(11),
score int

请用一条sql查出 >80分的科目列表,且用一行记录展示

SELECT 
  name AS studentName,
  JSON_ARRAYAGG(course) AS courseNameList
FROM student
WHERE score > 80
GROUP BY studentName;

参考

https://database.guide/json_arrayagg-create-a-json-array-from-the-rows-of-a-query-in-mysql/