Solved

Query formation

Posted on 2012-04-11
3
431 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

776 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