MySQL行列转换

创建一个sc表并插入数据

方法一:

select distinct uid,

(select score from sc where s.uid=uid and course='语文')语文,

(select score from sc where s.uid=uid and course='数学')数学,

(select score from sc where s.uid=uid and course='英语')英语

from sc s;

方法二:

select * from sc where course='语文';

select * from sc where course='数学';

select * from sc where course='英语';

把这三条数据当做三个表
select y.uid,y.score 语文,s.score 数学,e.score 英语

from (SELECT * FROM `sc` where course='语文') y

left join (SELECT * FROM `sc` where course='数学') s

on y.uid=s.uid

left join (SELECT * FROM `sc` where course='英语') e

on y.uid=e.uid;

相关推荐
c***V323几秒前
免费的Web安全培训课程,OWASP Top 10
数据库·安全·web安全
e***749539 分钟前
Redis——使用 python 操作 redis 之从 hmse 迁移到 hset
数据库·redis·python
2501_941112071 小时前
深入理解Python的if __name__ == ‘__main__‘
jvm·数据库·python
2501_941112051 小时前
Python Lambda(匿名函数):简洁之道
jvm·数据库·python
合作小小程序员小小店1 小时前
web网页开发,在线短视频管理系统,基于Idea,html,css,jQuery,java,springboot,mysql。
java·前端·spring boot·mysql·vue·intellij-idea
猿小喵2 小时前
浅谈MySQL主从复制
数据库·mysql
_Minato_2 小时前
数据库知识整理——SQL访问控制
数据库
BullSmall2 小时前
高斯数据库 (GaussDB) 使用指南
数据库·gaussdb
马克学长2 小时前
SSM旅游管理系统3ohx4(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·旅游管理系统·ssm 框架
朝新_2 小时前
Spring事务和事务传播机制
数据库·后端·sql·spring·javaee