oracle字段范围查询

oralce中有一张表temp,表数据如下
name type

张三 test1

李四 test1

王五 test1

张三 test2

张三 test3
李四 test2

请问各位大神怎么能将上面的数据 进行统计转换成:

name test1 test2 test3
张三 1 1 1
李四 1 1 0
王五 1 0 0

统计name在type(所有值所构成的区间)的数目,按照name分组

用decode或者case when都可以实现的:
[code="sql"]
select t.name,
sum(decode(t.type, 'test1', 1, 0)) test1, sum(decode(t.type, 'test2', 1, 0)) test2, sum(decode(t.type, 'test3', 1, 0)) test3
from temp t
group by t.name
order by t.name

[/code]