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;

相关推荐
dust_and_stars6 分钟前
为什么ubuntu24 snap install code-server 不需要--classic?
网络·数据库
BomanGe29 分钟前
NSK W1406FA系列长行程高速精密丝杠技术指南
运维·服务器·数据库·经验分享·规格说明书
之歆14 分钟前
MongoDB 深度解析:从原理到实践的完整指南
数据库·mongodb
一 乐15 分钟前
幼儿园管理系统|基于springboot + vue幼儿园管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·幼儿园管理系统
tiancaijiben16 分钟前
阿里云日志服务SLS全流程对接与深度使用指南
网络·数据库
云计算磊哥@19 分钟前
运维开发宝典028-MySQL04数据库热备
数据库·adb·运维开发
五阿哥永琪32 分钟前
正则表达式
数据库·mysql·正则表达式
LaughingZhu40 分钟前
Product Hunt 每日热榜 | 2026-06-13
数据库·mysql
c238561 小时前
GDB 进程概念详解(下篇)—— 多进程与进阶调试能力
linux·服务器·数据库
tiancaijiben1 小时前
阿里云云备份(Cloud Backup)全量对接与使用指南
数据库·oracle