?
Solved

need some modification in query

Posted on 2014-02-19
3
Medium Priority
?
268 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 29

Accepted Solution

by:
MikeOM_DBA earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
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.
This video shows how to recover a database from a user managed backup
Suggested Courses

762 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