1.1 建表
create table test
(
id NUMBER,
name VARCHAR(300),
test1 VARCHAR(300),
test2 NUMBER
);
1.2插入数据
insert into test (id,name,test1,test2) values(1,'小王','语文成绩',80);
insert into test (id,name,test1,test2) values(2,'小王','数学成绩',70);
insert into test (id,name,test1,test2) values(3,'小王','英语成绩',60);
2.1、Decode方法
select name,
sum(DECODE(test1,'语文成绩',test2,0)) as 苹果,
sum(DECODE(test1,'数学成绩',test2,0)) as 香蕉,
sum(DECODE(test1,'英语成绩',test2,0)) as 哈密瓜
from test
GROUP BY NAME
2.2、wm_concat方法
select name, wm_concat(test1), wm_concat(test2) from test GROUP BY NAME
应该还会有其他的方法,欢迎各位小伙伴补充
网友评论