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;

相关推荐
岁岁种桃花儿11 小时前
MySQL从入门到精通系列:InnoDB记录存储结构
数据库·mysql
jiunian_cn12 小时前
【Redis】hash数据类型相关指令
数据库·redis·哈希算法
冉冰学姐12 小时前
SSM在线影评网站平台82ap4(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
数据库·ssm框架·在线影评平台·影片分类
Exquisite.13 小时前
企业高性能web服务器(4)
运维·服务器·前端·网络·mysql
知识分享小能手13 小时前
SQL Server 2019入门学习教程,从入门到精通,SQL Server 2019数据库的操作(2)
数据库·学习·sqlserver
踩坑小念14 小时前
秒杀场景下如何处理redis扣除状态不一致问题
数据库·redis·分布式·缓存·秒杀
萧曵 丶15 小时前
MySQL 语句书写顺序与执行顺序对比速记表
数据库·mysql
Wiktok16 小时前
MySQL的常用数据类型
数据库·mysql
曹牧16 小时前
Oracle 表闪回(Flashback Table)
数据库·oracle
J_liaty16 小时前
Redis 超详细入门教程:从零基础到实战精通
数据库·redis·缓存