create table student(
name varchar2(30),
gj varchar2(20),
score number(4,1)
);
insert into student (name, gj, score) values ('李二', '中國', 90);
insert into student (name, gj, score) values ('張無忌', '美國', 80);
insert into student (name, gj, score) values ('周芷若', '俄羅斯', 79);
insert into student (name, gj, score) values ('xx', '中國', 95);
insert into student (name, gj, score) values ('hh', '美國', 85);
insert into student (name, gj, score) values ('kk', '俄羅斯', 77);
select count(u.xm) as 總?cè)藬?shù),
sum(decode(u.gj, 1, u.cj)) as 中國成績,
sum(decode(u.gj, 2, u.cj)) as 美國成績,
sum(decode(u.gj, 3, u.cj)) as 俄羅斯成績
From (select name as xm,
decode(gj, '中國', 1, '美國', 2, '俄羅斯', 3) as gj,
sum(score) as cj
from student
group by name,gj) u;