mysql行转列多行一列转一行多列

round1

select 95 as score
union all
select 85
union all 
select 100

在这里插入图片描述
round2

select 'star' as biz,95 as score
union all
select 'moon',85
union all 
select 'sun',100

在这里插入图片描述
round3

select case when biz='star' then score end as star,
case when biz='moon' then score end as moon,
case when biz='sun' then score end as sun
from(
select 'star' as biz,95 as score
union all
select 'moon',85
union all 
select 'sun',100) a

在这里插入图片描述
round4

select max(case when biz='star' then score end) as star,
max(case when biz='moon' then score end) as moon,
max(case when biz='sun' then score end) as sun
from(
select 'star' as biz,95 as score
union all
select 'moon',85
union all 
select 'sun',100) a

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43275277/article/details/130811143