Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
427 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...