热线电话:13121318867

登录
2021-04-30 阅读量: 3146
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
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子