mysql row to column to multiple rows and one column to one row to multiple columns

round1

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

Insert image description here
round2

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

Insert image description here
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

Insert image description here
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

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_43275277/article/details/130811143