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;

相关推荐
云和数据.ChenGuang10 分钟前
运维故障之MySQL 连接授权错误
运维·数据库·人工智能·mysql
枫叶梨花26 分钟前
Greenplum数据库身份证查验函数
数据库
Pocker_Spades_A36 分钟前
数据库的“多模融合”——金仓
数据库
Maggie_ssss_supp1 小时前
Linux-MySQL数据类型&表操作
数据库·mysql
廋到被风吹走1 小时前
【数据库】【MySQL】高可用架构深度解析:从主从复制到自动切换
数据库·mysql·架构
IT邦德1 小时前
PostgreSQL 通过 mysql_fdw连通MySQL实战
数据库·mysql·postgresql
難釋懷1 小时前
Redis 通用命令
数据库·redis·缓存
hanqunfeng1 小时前
(九)Redis 命令及数据类型 -- Set
数据库·redis·bootstrap
企业对冲系统官1 小时前
期货与期权一体化平台风险收益评估方法与模型实现
运维·服务器·开发语言·数据库·python·自动化
IT邦德1 小时前
PostgreSQL通过Oracle_FDW连通Oracle实战
数据库·postgresql·oracle