【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/

【MySQL】行转列

上一篇:SpringBoot 之 Dao层模拟数据库操作


下一篇:mysql基本使用