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;

相关推荐
百***49003 分钟前
Redis-配置文件
数据库·redis·oracle
老纪的技术唠嗑局5 分钟前
OceanBase 年度发布会 Hands-on AI Workshop 回顾
数据库
艾体宝IT9 分钟前
艾体宝干货 | Redis Python 开发系列#5 高可用与集群部署指南
数据库
d***956210 分钟前
docker 安装 mysql
mysql·adb·docker
雨中飘荡的记忆14 分钟前
MySQL 优化实战
java·mysql
3***891917 分钟前
开放自己本机的mysql允许别人连接
数据库·mysql·adb
X***C86221 分钟前
使用bitnamiredis-sentinel部署Redis 哨兵模式
数据库·redis·sentinel
f***019323 分钟前
CC++链接数据库(MySQL)超级详细指南
c语言·数据库·c++
q***235724 分钟前
MySQL 篇 - Java 连接 MySQL 数据库并实现数据交互
java·数据库·mysql
W***952426 分钟前
在Spring Boot项目中使用MySQL数据库
数据库·spring boot·mysql