Solved

need some modification in query

Posted on 2014-02-19
3
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 77

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

726 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