2012-03-06 71 views
1

我有一个表甲骨文行至列转换

select * from table

值返回被

login id | status_name | count 
=============================== 
admin | open  |  3 
admin | closed  |  5 
test  | inprogress | 10 
test  | open  | 10 
test  | closed  | 11 
user1 | closed  |  5 
user1 | pending  | 10 

如何从行转移该数据列? 我想以这种方式

login_id | open | closed | inprogress | pending 
================================================ 
admin | 3 |  5 |   0 |  0 
test  | 10 |  10 |   10 |  0 
user1 | 0 |  5 |   0 |  10 
+0

尝试寻找到PIVOT还有:如http://stackoverflow.com/questions/4841718/oracle-sql-pivot-query – tbone 2012-03-06 12:12:43

回答

3
select login_id 
    , sum(case when status_name='open' then count end) open 
    , sum(case when status_name='closed' then count end) closed 
    , sum(case when status_name='inprogress' then count end) inprogress 
    , sum(case when status_name='pending' then count end) pending 
from table 
group by login_id 
+0

喜...感谢提供查询但计数没有显示出来....还有什么办法可以写出动态的 – user1251973 2012-03-06 11:59:13