Solved

Query formation

Posted on 2012-04-11
3
433 Views
Last Modified: 2012-04-14
Hi,

Is it possible to rewrite the below query any differently.
I think it is little bit redundant and it takes up some extra cost but I don't know how to rewrite this to get..please help.

SELECT distinct a.ord_id cancelled_ord_id, a.last_ord_id AS rebilled_order_id, a.acct_nr, 'TOTAL' as Type    
  FROM sir_invc a, SIR_INVC_CNCLTN_RQST ICR  
WHERE  
 a.ord_id not in (                  
                                 
                 select distinct b.last_ord_id from sir_invc b, SIR_INVC_CNCLTN_RQST ICR
                     where
                   b.last_ord_id is not null
                     and b.bilng_in68_cd = 129
                     and b.wrhs_cd = 37
                     and b.zone_cd = 1                  
                        AND ICR.ACCOUNT_NUMBER =  b.acct_nr
                   AND ICR.CAMPAIGN_YEAR =   b.cmpgn_yr
                 AND ICR.CAMPAIGN_NUMBER = b.cmpgn_nr
                 AND ICR.ord_id = b.ord_id
                 AND ICR.invc_cncltn_answr_dt is not null
                 AND TO_CHAR(ICR.WORK_DT,'DD-MM-YYYY') = '11-04-2012'      
                 AND b.last_point_trkg_cd = 10      
                   
                     )

and a.last_ord_id is null
and a.last_point_trkg_cd = 10
and a.bilng_in68_cd = 129
and a.wrhs_cd = 37
and a.zone_cd = 1
AND ICR.ACCOUNT_NUMBER =  a.acct_nr
AND ICR.CAMPAIGN_YEAR =   a.cmpgn_yr
AND ICR.CAMPAIGN_NUMBER = a.cmpgn_nr
AND ICR.ord_id = a.ord_id
AND ICR.invc_cncltn_answr_dt is not null
AND TO_CHAR(ICR.WORK_DT,'DD-MM-YYYY') = '11-04-2012'


Best Regards,
Neoarwin
0
Comment
Question by:neoarwin
[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
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 37836203
SELECT distinct a.ord_id cancelled_ord_id, a.last_ord_id AS rebilled_order_id, a.acct_nr, 'TOTAL' as Type    
  FROM sir_invc a, SIR_INVC_CNCLTN_RQST ICR  
WHERE  
 a.ord_id not in (                  
                                 
                 select b.last_ord_id from sir_invc b, SIR_INVC_CNCLTN_RQST c
                     where
                     and b.bilng_in68_cd = a.bilng_in68_cd
                     and b.wrhs_cd = a.wrhs_cd
                     and b.zone_cd = a.zone_cd
                        AND c.ACCOUNT_NUMBER =  b.acct_nr
                   AND c.CAMPAIGN_YEAR =   b.cmpgn_yr
                 AND c.CAMPAIGN_NUMBER = b.cmpgn_nr
                 AND c.ord_id = b.ord_id
                 AND c.invc_cncltn_answr_dt is not null
                 AND TRUNC(c.WORK_DT) = TRUNC(a.WORK_DT)
                 AND b.last_point_trkg_cd = a.last_point_trkg_cd
                   
                     )

and a.last_ord_id is null
and a.last_point_trkg_cd = 10
and a.bilng_in68_cd = 129
and a.wrhs_cd = 37
and a.zone_cd = 1
AND ICR.ACCOUNT_NUMBER =  a.acct_nr
AND ICR.CAMPAIGN_YEAR =   a.cmpgn_yr
AND ICR.CAMPAIGN_NUMBER = a.cmpgn_nr
AND ICR.ord_id = a.ord_id
AND ICR.invc_cncltn_answr_dt is not null
AND TO_CHAR(ICR.WORK_DT,'DD-MM-YYYY') = '11-04-2012'
0
 
LVL 42

Expert Comment

by:dqmq
ID: 37837792
Remove the first "distinct" will also improve performance, but I don't know if it would change the results.    And other performance improvements may be possible, but I cannot discern as much without a data model.
0
 

Author Closing Comment

by:neoarwin
ID: 37846209
Thanks
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.

730 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