日期:2014-05-19 浏览次数:20821 次
select name, sum(decode(subject,'语文', score,null)) "语文", sum(decode(subject,'数学', score,null)) "数学", sum(decode(subject,'英语', score,null)) "英语" from testTable t group by name;
------解决方案--------------------
相关子查询法
设你的表名是tablename
select name,
(select score from tablename where name = t.name and subject = '语文'),
(select score from tablename where name = t.name and subject = '数学'),
(select score from tablename where name = t.name and subject = '英语')
from tablename t
group by name;
你试试看,我没做测试。
------解决方案--------------------
select name,
sum(decode(subject,'语文', score,0)) 语文,
sum(decode(subject,'数学', score,0)) 数学,
sum(decode(subject,'英语', score,0)) 英语
from userTable t
group by name;