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;

相关推荐
牵牛老人38 分钟前
Qt C++ 复杂界面处理:巧用覆盖层突破复杂界面处理难题之一
数据库·c++·qt
a_blue_ice41 分钟前
JAVA 面试 MySQL
java·mysql·面试
GBASE44 分钟前
GBASE南大通用技术分享:构建最优数据平台,GBase 8s数据库安装准备(三)
数据库
言之。1 小时前
Django REST Framework 中 @action 装饰器详解
数据库·sqlite
十八旬3 小时前
苍穹外卖项目实战(day7-1)-缓存菜品和缓存套餐功能-记录实战教程、问题的解决方法以及完整代码
java·数据库·spring boot·redis·缓存·spring cache
Java水解4 小时前
【MySQL】数据库基础
后端·mysql
沃夫上校4 小时前
MySQL 中文拼音排序问题
java·mysql
要一起看日出4 小时前
MVCC-多版本并发控制
数据库·mysql·mvcc
Hx__4 小时前
MySQL InnoDB 的 MVCC 机制
数据库·mysql
速易达网络4 小时前
ASP.NET MVC 连接 MySQL 数据库查询示例
数据库·asp.net·mvc