首页 > 数据库技术 > 详细

【MySQL】行转列

时间:2020-05-03 13:33:59      阅读:51      评论:0      收藏:0      [点我收藏+]
给定学生表如下

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】行转列

原文:https://blog.51cto.com/l0vesql/2492159

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!