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;

相关推荐
WX-bisheyuange7 分钟前
基于Spring Boot的智慧校园管理系统设计与实现
java·大数据·数据库·毕业设计
JavaGuide40 分钟前
对标MinIO!全新一代分布式文件系统诞生!
数据库·后端
快乐非自愿1 小时前
数据库如何处理大量的交易流水记录
数据库·oracle
IvorySQL1 小时前
瀚高硬核助力 PG 社区:Postgres 19 迎来并行 TID 范围扫描,速度提升 3 倍
数据库·postgresql·开源
ServBay1 小时前
MongoDB 的文档模型与 CRUD 实战
数据库·后端·mongodb
ITMr.罗1 小时前
深入理解EF Core更新机制(开发中因为省事遇到的问题)
服务器·数据库·c#·.net
梁萌1 小时前
MySQL索引的使用技巧
数据库·mysql·索引·b+tree
x10n92 小时前
OceanBase 参数对比工具 附源码
数据库·vscode·oceanbase·腾讯云ai代码助手
RestCloud2 小时前
如何用ETL做实时风控?从交易日志到告警系统的实现
数据库·数据仓库·kafka·数据安全·etl·数据处理·数据集成
云和恩墨3 小时前
MySQL和PostgreSQL谁更适合AI时代?
数据库