Skip to Main Content

SQL & PL/SQL

Need some help with PIVOT

2788234Nov 4 2014 — edited Nov 5 2014

Hello,

First, let me apologize if this is in the wrong forum.

I need some help with the pivot command in Oracle.  Here is what I am trying to accomplish:

select persongroup,status, count(status) as tot

from workorder

where status in ('WSCH','WPLAN','WMATL','PLAN','APPR')

and persongroup in ('K3P-GEN','K3P-ELEC','K3P-INST','K3P-MECH')

group by  persongroup,status

order by 1


Results:


K3P-ELEC APPR 12

K3P-ELEC PLAN 10

K3P-ELEC WMATL 10

K3P-ELEC WPLAN 109

K3P-ELEC WSCH 18

K3P-GEN APPR 17

K3P-GEN PLAN 59

K3P-GEN WMATL 10

K3P-GEN WPLAN 188

K3P-GEN WSCH 22

K3P-INST APPR 18

K3P-INST PLAN 27

K3P-INST WMATL 17

K3P-INST WPLAN 60

K3P-INST WSCH 40

K3P-MECH APPR 4

K3P-MECH PLAN 47

K3P-MECH WMATL 14

K3P-MECH WPLAN 20

K3P-MECH WSCH 52

What I want to see is :

                        APPR     PLAN     WMATL     WPLAN     WSCH     TOTAL

K3P-ELEC         12          10               10               109          18          159

K3P-GEN          17          59               10               188           22          296

......

Using the query above I tried this but it is incorrect;

select * from (

select persongroup,status, count(status) as tot

from   workorder

where status in ('WSCH','WPLAN','WMATL','PLAN','APPR')

and persongroup in ('K3P-GEN','K3P-ELEC','K3P-INST','K3P-MECH')

group by  persongroup,status

order by 1

  sum(3)

  for status in ('WSCH','WPLAN','WMATL','PLAN','APPR')

order by 1



Any help appreciated.


Thank you


Cameron

This post has been answered by L-MachineGun on Nov 4 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2014
Added on Nov 4 2014
4 comments
156 views