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;

相关推荐
byxdaz22 分钟前
jeston平台交叉编译Poppler库与预览pdf文件
数据库
SilicoCode28 分钟前
江科大STM32入门:FLASH闪存详解——从结构原理到读写保护
数据库·mongodb
一个有温度的技术博主1 小时前
DeepSeek Harness 深度解析:与 LangChain / LangGraph 的本质区别
数据库·oracle·langchain·harness
Wang's Blog2 小时前
PostgreSQL笔记4: 市场地位、生态全景与行业应用实践
数据库·笔记·postgresql
隔窗听雨眠3 小时前
Oracle误Truncate操作恢复:从原理到实战的完整指南
数据库·oracle
Lethehong3 小时前
MySQL迁移如何做到零改造?四层兼容方案详解
数据库·mysql·adb
Json____3 小时前
五金制品行业-企业官网源码
java·大数据·数据库·企业站·wwwoop.com
深念Y5 小时前
Opencode Event 表写入优化方案
数据库·人工智能·ai·node.js·bug·优化·opencode
竹枝溪6 小时前
MySQL进阶:约束、多表设计、多表查询与事务
java·数据库·mysql·事务·子查询·acid·多表查询
技术长镜头6 小时前
别再只会“加索引”:从磁盘页到 B+Tree,彻底理解 MySQL 索引的设计与运行
后端·mysql