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;

相关推荐
RestCloud3 小时前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud3 小时前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence5 小时前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
Java水解7 小时前
Mysql查看执行计划、explain关键字详解(超详细)
后端·mysql
知其然亦知其所以然10 小时前
MySQL 社招必考题:如何优化查询过程中的数据访问?
后端·mysql·面试
DemonAvenger12 小时前
NoSQL与MySQL混合架构设计:从入门到实战的最佳实践
数据库·mysql·性能优化
程序新视界12 小时前
如何在MySQL中创建聚集索引?
mysql
AAA修煤气灶刘哥1 天前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
程序新视界1 天前
学习MySQL绕不开的两个基础概念:聚集索引与非聚集索引
mysql
RestCloud1 天前
跨境数据传输:ETL如何处理时区与日期格式差异
mysql·api