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;

相关推荐
864记忆19 分钟前
Qt创建连接注意事项
数据库·qt·nginx
小小bugbug43 分钟前
mysql查询的原始返回顺序与limit分页优化
mysql·adb
毕设十刻1 小时前
基于Vue的迅读网上书城22f4d(程序 + 源码 + 数据库 + 调试部署 + 开发环境配置),配套论文文档字数达万字以上,文末可获取,系统界面展示置于文末
前端·数据库·vue.js
薛定谔的猫19821 小时前
Langchain(十二)LangGraph 实战入门:用流程图思维构建 LLM 工作流
数据库·microsoft
坐吃山猪2 小时前
ChromaDB02-代码实战
数据库·向量数据库·chromadb
摇滚侠2 小时前
MySQL 中 utf8mb4 字符集,字母a占几个字节,一个汉字占几个字节 / MySQL 中 utf8mb3 字符集,字母a占几个字节,一个汉字占几个字节
数据库·mysql
ChineHe2 小时前
Redis数据类型篇001_数据类型梳理与选择指南
数据库·redis·缓存
Antoine-zxt2 小时前
MySQL CPU飙升至500%的深度排查与优化实践
数据库·mysql
Awkwardx2 小时前
MySQL数据库—MySQL基本查询
数据库·mysql
夜流冰2 小时前
Excel - MS Support for Excel: 2 Collaborate
数据库·windows·excel