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;

相关推荐
有味道的男人20 分钟前
对接亚马逊平台接口,商品全量信息一键抓取
数据库
Web极客码38 分钟前
2026年Linux VPS安全加固清单:SSH、防火墙与审计就绪配置
运维·服务器·数据库
逻辑驱动的ken2 小时前
Java高频面试考点18
java·开发语言·数据库·算法·面试·职场和发展·哈希算法
qq_392690662 小时前
Redis怎样应对Redis集群整体宕机带来的雪崩
jvm·数据库·python
快乐非自愿3 小时前
Redis--SDS字符串与集合的底层实现原理
数据库·redis·缓存
这儿有一堆花3 小时前
住宅代理(Residential Proxy)技术指南
开发语言·数据库·php
茉莉玫瑰花茶4 小时前
LangChain 核心组件 [ 2 ]
java·数据库·langchain
存在的五月雨4 小时前
Mysql 索引的一些
数据库·mysql
黄俊懿5 小时前
MySQL主从复制:从“异步“到“GTID“,数据同步的进化之路
数据库·sql·mysql·oracle·架构·dba·db
看海的四叔5 小时前
【SQL】SQL-管好你的字符串
大数据·数据库·hive·sql·数据分析·字符串