Solved

need some modification in query

Posted on 2014-02-19
3
263 Views
Last Modified: 2014-02-19
Hello Expert,

i am using oracle 11g.

below is my query

 

 SELECT a.year_quater,

 

       NVL(a.region_ls,a.region_wp) AS Region,

       count(DECODE(a.final_disposition,'10',1)) as BRC,

       count(DECODE(a.final_disposition,'20',1)) as RO,

       count(DECODE(a.final_disposition,'40',1)) as WPC,

       count(DECODE(a.final_disposition,'30',1)) as Merged,

       count(DECODE(a.final_disposition,'60',1)) as Dropped

FROM ms_fcr_issue a

group by a.year_quater,NVL(a.region_ls,a.region_wp)

order by Region

my out put is like this

Year_Quarter   Region                         BRC     RO      WPC  MERGED  DROPPED

2013-Q1           EMEA                               1         0           0         0                   0

2013-Q2           NAM,APAC,LATAM         1         0           0         0                   0      

2013-Q3           EMEA                                1         1           0        0                    0

2013-Q4           LATAM                               1         0           1        1                   0

but i need output  like  instead of 2013-Q1  need below only Q1 Q2....

                     2013-Q1      2013- Q2  2013- Q3    2013-Q4      

BRC                            

RO

WPC

MERGED

DROPPED

Regards

Damby
0
Comment
Question by:deve_thomos
3 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39870472
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
ID: 39870633
Try this:
SQL> l
  1  WITH Ms_Fcr_Issue (Region_Ls, Region_Wp, Final_Disposition, Year_Quarter)
  2       AS (SELECT 'EMEA', '', '20', '2013-Q1' FROM DUAL UNION
  3           SELECT '', 'NAM,APAC,LATAM', '10', '2013-Q2' FROM DUAL UNION
  4           SELECT 'EMEA', '', '10', '2013-Q3' FROM DUAL UNION
  5           SELECT 'EMEA', '', '20', '2013-Q3' FROM DUAL UNION
  6           SELECT '', 'LATAM', '10', '2013-Q4' FROM DUAL UNION
  7           SELECT '', 'LATAM', '40', '2013-Q4' FROM DUAL UNION
  8           SELECT '', 'LATAM', '30', '2013-Q4' FROM DUAL)
  9     , Codes (Cd, Cdesc)
 10       AS (SELECT '10', 'BRC' FROM DUAL UNION
 11           SELECT '20', 'RO' FROM DUAL UNION
 12           SELECT '30', 'MERGED' FROM DUAL UNION
 13           SELECT '40', 'WPC' FROM DUAL UNION
 14           SELECT '60', 'DROPPED' FROM DUAL)
 15  SELECT * FROM (
 16  SELECT K.Cdesc, Year_Quarter
 17    FROM Ms_Fcr_Issue A, Codes K
 18   WHERE K.Cd = A.Final_Disposition(+))
 19*  PIVOT (count(*) for Year_Quarter IN ('2013-Q1','2013-Q2','2013-Q3','2013-Q4'))
SQL> /

CDESC               '2013-Q1'  '2013-Q2'  '2013-Q3'  '2013-Q4'
------------------ ---------- ---------- ---------- ----------
BRC                         0          1          1          1
WPC                         0          0          0          1
RO                          1          0          1          0
MERGED                      0          0          0          1
DROPPED                     0          0          0          0

Open in new window

0
 

Author Closing Comment

by:deve_thomos
ID: 39872502
Thanks a lot
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now