转置(旋转)一张数据库表

时间:2021-09-11 05:59:27

题目:有如下二维表:

转置(旋转)一张数据库表

create table student(
name varchar2(10),
cno char(2),
cource varchar2(10),
score number(2)
)
insert into student values('S1','C1','数据结构 ','91') ;
insert into student values('S1','C2','操作系统','81') ;
insert into student values('S1','C3','微积分','71') ;
insert into student values('S2','C1','数据结构','92') ;
insert into student values('S2','C2','操作系统','82') ;
insert into student values('S2','C3','微积分','72') ;
insert into student values('S3','C1','数据结构','93') ;
insert into student values('S3','C2','操作系统','83') ;
insert into student values('S3','C3','微积分','73') ;
参考答案: select s11.name "姓名", s11.score "数据结构",
s12.score "操作系统", s13.score "微积分"
from (select name, score from student where cno = 'C1') s11,
(select name, score from student where cno = 'C2') s12,
(select name, score from student where cno = 'C3') s13
where s11.name = s12.name
and s12.name = s13.name