liting李

2021-04-30   阅读量: 2606

Mysql

mysql怎么进行行列转置

扫码加入数据分析学习群

原表:

image.png

怎么行列进行转换像下图这样呢?

image.png

答:用case when函数

select username '姓名',

MAX(case course when '语文' then score else 0 end) '语文',

MAX(case course when '数学' then score else 0 end) '数学',

MAX(case course when '外语' then score else 0 end) '外语'

from tb_RowConvertToColumn

group by username

order by username;

即可实现

137.4878 3 0 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子