固定列数的行列转换

create  table "student"
(
  id number(11,0),
  stuname varchar2(20),
  subject varchar(20),
  grade number(4,2),
  primary key(id)
)

 

insert into "student" values(201001,'javazhou','语文',90);
insert into "student" values(201002,'javazhou','数学',99);
insert into "student" values(201003,'javazhou','英语',80);
insert into "student" values(201004,'xiaoju','语文',90);
insert into "student" values(201005,'xiaoju','数学',70);
insert into "student" values(201006,'xiaoju','英语',98);


select stuname, sum(decode(subject,'语文',grade,null)) "语文" ,
sum(decode(subject,'数学',grade,null)) "数学",
sum(decode(subject,'英语',grade,null))  "英语"
from "student"
group by stuname
 

你可能感兴趣的:(行列转换)