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;

相关推荐
TDengine (老段)23 分钟前
TDengine 数学函数 PI 用户手册
大数据·数据库·时序数据库·iot·tdengine·涛思数据
aristo_boyunv26 分钟前
Redis发布订阅【充当消息中间件】
数据库·redis·缓存
zz-zjx1 小时前
MySQL 开源主从复制实战指南(SRE 可靠性优先版)
数据库·mysql·开源
计算机学姐4 小时前
基于微信小程序的高校班务管理系统【2026最新】
java·vue.js·spring boot·mysql·微信小程序·小程序·mybatis
Microsoft Word8 小时前
向量数据库与RAG
数据库·人工智能·向量数据库·rag
位步9 小时前
在linux系统中使用通用包安装 Mysql
android·linux·mysql
艾德金的溪9 小时前
redis-7.4.6部署安装
前端·数据库·redis·缓存
小光学长9 小时前
基于Vue的2025年哈尔滨亚冬会志愿者管理系统5zqg6m36(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
前端·数据库·vue.js
小陈永不服输10 小时前
MySQL覆盖索引深度解析:从原理到实践的性能优化之道
mysql