oracle 如何实现各字段的类加,具全例子如下:
代码如下:
select * from student;
select * from subject;
select * from sccore;
select * from student;
select * from subject;
select a.name,
sum(case when b.subname='语文' then c.score else 0 end) As "语文" ,
sum(case when b.subname='数学' then c.score else 0 end) As "数学",
sum(case when b.subname='英语' then c.score else 0 end) As "英语",
sum(c.score) as "总分"
from student a,subject b,sccore c
where a.stuid=c.stuid and c.subid=b.subid
Group By name;
效果如下图:
NAME 语文 数学 英语 总分
-------------------------------------------------- ---------- ---------- ---------- ----------
王明 98 88 95 281
甘建 98 78 99 275
要求如下:在此SQL语句中如何实现,语文成绩,数学成绩,英语成绩,总分的类加,就是让各类相关。如何实现,
急急急!!!
------解决方案--------------------
你可以使用
GROUP BY GROUPING SETS((),)这个试试
------解决方案--------------------
select * from student;
select * from subject;
select * from sccore;
select * from student;
select * from subject;
select a.name,
sum(case when b.subname='语文' then c.score else 0 end) As "语文" ,
sum(case when b.subname='数学' then c.score else 0 end) As "数学",
sum(case when b.subname='英语' then c.score else 0 end) As "英语",
sum(c.score) as "总分"
from student a,subject b,sccore c
where a.stuid=c.stuid and c.subid=b.subid
Group By Grouping Sets((name),());