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;

相关推荐
镜舟科技6 分钟前
如何高效使用 Text to SQL 提升数据分析效率?四个关键应用场景解析
数据库·sql·数据分析
玛奇玛丶16 分钟前
数据库索引失效了...
后端·mysql
King.62438 分钟前
数据服务化 VS 数据中台:战略演进中的价值重构
大数据·数据库·sql·oracle·重构
Elastic 中国社区官方博客39 分钟前
Elasticsearch:AI 助理 - 从通才到专才
大数据·数据库·人工智能·神经网络·elasticsearch·搜索引擎·全文检索
花千树-0101 小时前
MySQL 数据库备份和恢复全指南
数据库·mysql
·薯条大王1 小时前
Node.js 操作 MySQL 数据库
javascript·数据库·mysql
Java_SuSheng1 小时前
关于SQLite轻量数据库的研究
java·数据库·spring boot·sqlite·mybatis
maomi_95263 小时前
数据库学习通期末复习二
服务器·数据库
努力努力再努力wz3 小时前
【Linux实践系列】:用c/c++制作一个简易的进程池
linux·运维·数据库·c++·c
fly spider4 小时前
一站式Windows下Docker开启MySQL并链接本地Navicat(附乱码解决方案)
windows·mysql·docker·乱码解决