答案 0 :(得分:0)
select
'group_a' as groupname
, max( case classname when 'C123' then group_a else null end) as c123
, max( case classname when 'C456' then group_a else null end) as c456
from table1
union all
select
'group_b' as groupname
, max( case classname when 'C123' then group_b else null end) as c123
, max( case classname when 'C456' then group_b else null end) as c456
from table1
union all
select
'group_d' as groupname
, max( case classname when 'C123' then group_d else null end) as c123
, max( case classname when 'C456' then group_d else null end) as c456
from table1
union all
select
'group_e' as groupname
, max( case classname when 'C123' then group_e else null end) as c123
, max( case classname when 'C456' then group_e else null end) as c456
from table1