日期:2014-05-16 浏览次数:20827 次
with tbA as
(
select 'A' xm,'语文' km,90 fs,date'2013-01-01' rq from dual union all
select 'A' xm,'数学' km,91 fs,date'2013-01-01' rq from dual union all
select 'A' xm,'英语' km,92 fs,date'2013-01-01' rq from dual union all
select 'A' xm,'语文' km,90 fs,date'2013-02-01' rq from dual union all
select 'A' xm,'数学' km,91 fs,date'2013-02-01' rq from dual union all
select 'A' xm,'英语' km,92 fs,date'2013-02-01' rq from dual
)
select xm "姓名",rq "日期",
sum(decode(km,'语文',fs,0)) "语文",
sum(decode(km,'数学',fs,0)) "数学",
sum(decode(km,'英语',fs,0)) "英语"
from tbA
group by xm,rq
order by xm,rq
姓名 日期 语文 数学 英语
------------------------
1 A 2013/1/1 90 91 92
2 A 2013/2/1 90 91 92