[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Query formation

Posted on 2012-04-11
3
Medium Priority
?
438 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 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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.  …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

649 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