Solved

Oracle SQL - filter records not used

Posted on 2012-12-20
4
360 Views
Last Modified: 2012-12-21
Hello all

I have this SQL bellow that search for all TL_RATE used on LOAD and gives me a count on how many times they where used.

But i would like to do the opposite.

I would like to search all rates that was never used on a load. That, i really dont know what to start with.

Probably i just need to update the bellow SQL.

How can i do that?

Thanks again for your help.


Full SQL:
SELECT
    COUNT(DISTINCT BILL),
    LOAD.RATE_KEY,
    R.FROM_LOW_KEY_VALUE,
    R.FROM_HIGH_KEY_VALUE,
    R.FROM_COUNTRY,
    R.TO_LOW_KEY_VALUE,
    R.TO_HIGH_KEY_VALUE,
    R.TO_COUNTRY,
    LOAD.CARRIER_ID,
    TR.EFFECTIVE,
    TR.DATE_INVALID
FROM 
    LOAD, TL_RATE TR, LANE_RATE_NETWORK R
WHERE
    BEST_DEP > TO_DATE('20090830','YYYYMMDD')
    AND LOAD.RATE_KEY=TR.RATE_KEY
    AND TR.LANE_ID=R.ID
    GROUP BY LOAD.RATE_KEY,
    R.FROM_LOW_KEY_VALUE,
    R.FROM_HIGH_KEY_VALUE,
    R.FROM_COUNTRY,
    R.TO_LOW_KEY_VALUE,
    R.TO_HIGH_KEY_VALUE,
    R.TO_COUNTRY,
    LOAD.CARRIER_ID, 
    TR.EFFECTIVE,
    TR.DATE_INVALID
ORDER BY COUNT(DISTINCT BILL) DESC;

Open in new window

0
Comment
Question by:Wilder1626
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 38711243
Something like this should get you all the rates that aren't in load

select *
from tl_rate
where not (tl_rate.rate_key in (select load.rate_key from load))
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38711642
Hi sjwales

I think i'm missing one join somewhere cause i dont have any error and i done have any records also.

I think i have to also use this: AND TR.LANE_ID=R.ID
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38711662
I worked the code.

Let me test like this

SELECT   *
  FROM   TL_RATE
 WHERE   NOT (TL_RATE.RATE_KEY IN (SELECT   LOAD.RATE_KEY FROM LOAD)
              AND NOT (TL_RATE.LANE_ID IN
                             (SELECT   LANE_RATE_NETWORK.ID
                                FROM   LANE_RATE_NETWORK)))
         AND TL_RATE.DATE_INVALID >
               TO_DATE (TO_CHAR (SYSDATE, 'YYYYMMDD'), 'YYYYMMDD');

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 38713113
Many thanks for your help

all good now
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

803 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