原帖由 nokilled 于 2008-1-18 09:55 发表
---参考如下的看看能不能实现
[php]
SQL> select * from h_01;
NAME
OBJ
SCORE
-------------------- ---------- ----------
student1
语文
80
student1
数学
70
student1
英语
60
student2
语文
90
student2
数学
80
student2
英语
10
已选择6行。
SQL> select name,
2 sum(decode(obj, '语文', score, null)) 语文,
3 sum(decode(obj, '数学', score, null)) 数学,
4 sum(decode(obj, '英语', score, null)) 英语
5from h_01
6 group by name;
NAME
语文 数学 英语
-------------------- ---------- ---------- ----------
student1
80 70 60
student2
90 80 10
SQL>
[/php]
11g下面这么写也行吧?电脑上没装11g...
SELECT *
FROM h_01 PIVOT ( SUM (score) FOR obj IN ( '语文'' , '数学'' , '英语'' ) )
ORDER BY 1; |