Solved

need some modification in query

Posted on 2014-02-19
3
265 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dataware house query tuning 9 78
Oracle - Create Procedure with Paramater 16 63
Can i Import Access Table Into Oracle Using Toad 36 166
selective queries 7 27
Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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…

815 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

8 Experts available now in Live!

Get 1:1 Help Now