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;

相关推荐
IT邦德11 分钟前
GoldenGate 19C的静默安装及打补丁
数据库
吴佳浩 Alben12 分钟前
Go 1.22 通关讲解
开发语言·数据库·golang
yuniko-n34 分钟前
【力扣 SQL 50】子查询篇
数据库·sql·leetcode
roo_142 分钟前
【性能测试】图数据库的 benchmark
数据库
lhrimperial1 小时前
MySQL底层原理
java·后端·mysql
直有两条腿1 小时前
【Redis】原理-数据结构
数据结构·数据库·redis
韩立学长1 小时前
【开题答辩实录分享】以《植物园信息管理系统》为例进行选题答辩实录分享
java·数据库·spring
共享家95271 小时前
MySQL-基础查询(上)
mysql
问道飞鱼1 小时前
【数据库知识】PGSQL数据类型详细说明
数据库·sql·postgresql
I'm a winner1 小时前
【FreeRTOS实战】互斥锁专题:从理论到STM32应用题
数据库·redis·mysql