关闭

oracle行转列

430人阅读 评论(0) 收藏 举报
分类:

create table t(id number,name varchar2(10),subject varchar(10),score number(3));
insert into t values(1,'zs','语文',60);
insert into t values(1,'lisi','数学',70);
insert into t values(1,'wangwu','外语',80);
insert into t values(1,'zs','历史',90);
insert into t values(1,'lisi','英语',100);
insert into t values(1,'wangwu','语文',90);
insert into t values(1,'mh','语文',60);
select * from t

select name,
nvl(max(decode(subject,'语文',score)),0)语文,
nvl(max(decode(subject,'数学',score)),0)数学,
nvl(max(decode(subject,'外语',score)),0)外语,
nvl(max(decode(subject,'历史',score)),0)历史
from t group by name 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:22203次
    • 积分:559
    • 等级:
    • 排名:千里之外
    • 原创:33篇
    • 转载:12篇
    • 译文:0篇
    • 评论:1条