oracle数据库中用decode函数后,列变行怎么没有值了啊
selectt.sname姓名,sum(decode(t.ssc,'语文',t.zz))语文,sum(decode(t.ssc,'数学',t.zz))数学,sum(dec...
select t.sname 姓名,
sum(decode(t.ssc, '语文', t.zz)) 语文,
sum(decode(t.ssc, '数学', t.zz)) 数学,
sum(decode(t.ssc, '英语', t.zz)) 英语,
sum(decode(t.ssc, '历史', t.zz)) 历史
from (select m.mname sname, s.score zz, f.fname ssc
from member m, score s, f
where f.fid = s.fid
and m.mid = s.mid) t
group by t.sname;
其中 score 是成绩表包含
字段名称
SID
FID
MID
Score
课程表:F
字段名称
FID
FName
学生表:Member
字段名称
MID
MName 展开
sum(decode(t.ssc, '语文', t.zz)) 语文,
sum(decode(t.ssc, '数学', t.zz)) 数学,
sum(decode(t.ssc, '英语', t.zz)) 英语,
sum(decode(t.ssc, '历史', t.zz)) 历史
from (select m.mname sname, s.score zz, f.fname ssc
from member m, score s, f
where f.fid = s.fid
and m.mid = s.mid) t
group by t.sname;
其中 score 是成绩表包含
字段名称
SID
FID
MID
Score
课程表:F
字段名称
FID
FName
学生表:Member
字段名称
MID
MName 展开
1个回答
展开全部
select t.sname 姓名,
sum(nvl(decode(t.ssc, '语文', t.zz),0)) 语文,
sum(nvl(decode(t.ssc, '数学', t.zz),0)) 数学,
sum(nvl(decode(t.ssc, '英语', t.zz),0)) 英语,
sum(nvl(decode(t.ssc, '历史', t.zz),0)) 历史
from
(select m.mname sname, s.score zz, f.fname ssc
from member m, score s, f
where f.fid = s.fid
and m.mid = s.mid) t
group by t.sname;
都加上nvl试验一下
sum(nvl(decode(t.ssc, '语文', t.zz),0)) 语文,
sum(nvl(decode(t.ssc, '数学', t.zz),0)) 数学,
sum(nvl(decode(t.ssc, '英语', t.zz),0)) 英语,
sum(nvl(decode(t.ssc, '历史', t.zz),0)) 历史
from
(select m.mname sname, s.score zz, f.fname ssc
from member m, score s, f
where f.fid = s.fid
and m.mid = s.mid) t
group by t.sname;
都加上nvl试验一下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询