1

I have a table

select * from table

values returning are

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
John Doyle
  • 7,475
  • 5
  • 33
  • 40
user1251973
  • 341
  • 3
  • 7
  • 16
  • try looking into PIVOT as well: eg http://stackoverflow.com/questions/4841718/oracle-sql-pivot-query – tbone Mar 06 '12 at 12:12

1 Answers1

4
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
turbanoff
  • 2,439
  • 6
  • 42
  • 99
  • hi...thanks for the providing the query but count is not showing up....Also is there any way we can write dynamic – user1251973 Mar 06 '12 at 11:59