Oracle行到列的转换 [英] Oracle Rows to Column Transformation
本文介绍了Oracle行到列的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子
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
如何将这些数据从行转移到列? 我想要这种方式
how can i transfer this data from row to column? I want in this manner
login_id | open | closed | inprogress | pending
================================================
admin | 3 | 5 | 0 | 0
test | 10 | 10 | 10 | 0
user1 | 0 | 5 | 0 | 10
推荐答案
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
这篇关于Oracle行到列的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文