Decode the simple query

Decode the query
Simplified version of the query below.

SELECT
d.REG,
d.DP,
c.CHANNEL
Of
CUSTOMER c,.
ACCOUNT d
WHERE c.ID = d.ID
D.REG GROUP, d.DP, c.CHANNEL


Channel field in the Customer Table contains several store ID (1 Store, tray 2, tray 3, store 4 etc.) - basically, I want to use decode on the channel field so that instead of all the store ID being issued what is fate of the channel are
Store 1 = "big".
Store 2 = 'average '.
Store 3 = "Small".
All other stores = 'other '.

Where the decode to insert statement and what should be the format - attempt below
DECODE (c.CHANNEL, "keep 1, 'Big', ' Store 2', 'Medium', 'Store' 3', small ', 'Other' ') of

Hello

This should be what you are looking for:

SELECT   d.REG,
         d.DP,
         DECODE (c.CHANNEL, 'Store 1','Large', 'Store 2','Medium', 'Store 3','Small', 'Other') Channel
FROM     CUSTOMER c,
         ACCOUNT d
WHERE    c.ID = d.ID
GROUP BY d.REG,
         d.DP,
         c.CHANNEL

City where to move them in decoding...

Tags: Database

Similar Questions

  • Problem with the simple query.

    Hi all

    I am facing problem with the query below

    Select A.COL1, A.COL2

    B.COL1, B.COL2

    FROM TABLE1 A

    TABLE 1 B

    WHERE A.header = '123'

    AND B.header = '123'

    AND nvl (A.COL6, 'ABC') = 'ABC '.

    AND NVL (B.COL6, 'DEF') = 'DEF '.

    Basically, my requiremenyt is: I have only one table, TABLE1 here, which has a line two lines (for the same header) as "ABC" and another is "DEF". Table 1 has two columns (col1, col2) that should be displayed for both lines.

    When the header has two records in table1 top query works. and but if I do not have a record for any header example there are a record for "abc" in col6 only. so my query above does not work because there is no record for 'DEF' in col6. But I want to again request to fecth the output (for b.col1 and b.col2 should have null values)

    could you pls suggest me how to get the 4 columns.

    Thanks in advance

    Kind regards

    UVA.

    Try to place the status of outer join on column: analytical_criterion_code as

    and nvl (AUDIT.analytical_criterion_code, 'AUDIT2') = 'verification2. '

    .

    .

    and nvl (TRANS.analytical_criterion_code, 'TRANS2') = 'TRANS2.

    In the sub query based on the opinions that you have given in post # 1, although there is no value "DEF * ' for col6 due to the condition of outer join on b.col6 (+) line is extracted with b.col [1,2,3] as NULL values. Try to remove the (+) sign b.col6 and test.

    with t as)

    Select 111 col1, col2 'aaa', 'ABC' col6 123 header of all the double union

    Select 222 'bbb', 'DEF' col6, 123 double header

    )

    q as (select 123 double header)

    Select A.COL1, A.COL2, A.COL6

    B.COL1, B.COL2, b.COL6

    q.header

    T a

    t b

    q

    where a.col6 (+) = 'ABC '.

    and b.col6 (+) = "DEF."

    and q.header = a.header (+)

    and q.header = b.header (+)

  • Better way to write the simple query?

    I'm trying to get the date of 'busy' max 'mansion '.

    It is an example, I imagined, since I can't post our actual data. The following query works, but is their path easier.
    CREATE TABLE TEST_TABLE (  
    LOAN_NUMBER                 VARCHAR2(15 Byte),
    UN_ID                       NUMBER,
    CHANGE_DATE                 DATE,
    PROP_TYPE                   VARCHAR2(25 Byte),
    OCCSTAT                     VARCHAR2(25 Byte)
    ); 
    COMMIT;
    
    
    INSERT INTO TEST_TABLE VALUES (123456,  1,'01-JAN-09','Tent','Occupied');
    INSERT INTO TEST_TABLE VALUES (123456,  2,'01-FEB-09','Shack','Occupied');
    INSERT INTO TEST_TABLE VALUES (123456,  3,'01-JUN-08','Single Family','Occupied');
    INSERT INTO TEST_TABLE VALUES (123456,  4,'01-OCT-08','Single Family Plus','Occupied');
    INSERT INTO TEST_TABLE VALUES (123456,  5,'01-DEC-08','Mansion','Occupied');
    INSERT INTO TEST_TABLE VALUES (123456,  6,'05-JAN-09','Mansion','Unoccupied');
    COMMIT;
    Reason, I take the ID's for the second join because I know that the ID max = max.
    select     
    i2.UN_ID,
    i2.CHANGE_DATE,
    i2.PROP_TYPE,
    i2.OCCSTAT
    from 
    (
        select 
            distinct(LOAN_NUMBER) AS "LOAN_ID", 
            max(UN_ID) AS "ID_MAX"
        from(
        select 
            LOAN_NUMBER,
            UN_ID
      from
            TEST_TABLE
        where OCCSTAT = 'Occupied'
        group by LOAN_NUMBER, UN_ID
        ) 
        group by LOAN_NUMBER
    )i
    left join TEST_TABLE i2 on i.ID_MAX = i2.UN_ID
    easier way without the second join?

    Thanks in advance.

    R

    Try this query, it should be equivalent to your:

    select UN_ID, CHANGE_DATE, PROP_TYPE, OCCSTAT
    from (
        select LOAN_NUMBER, UN_ID, CHANGE_DATE, PROP_TYPE, OCCSTAT, rank() over(partition by LOAN_NUMBER order by un_id desc) rn
        from test_table
         where OCCSTAT = 'Occupied'
    )
    where rn=1
    

    Max

  • How to make the simple query for this scenario... ?

    Hello:

    Dummy table provided for simplicity.

    It's my database table (Table_A)

    Date1 | Plane1 | Category | Duration | Fees
    01/01/2011 | A | Gold | 5. 2
    01/01/2011 | C | Money | 4. 11
    01/01/2011 | B | Gold | 6. 2
    01/01/2011 | D | Gold | 2. 4
    01/01/2011 | B | Gold | 3. 5
    01/01/2011 | A | Money | 4. 8
    01/01/2011 | B | Gold | 1. 3

    I need to write a query to get the result below:

    Date1 | Plane1 | Sum_Duration | Sum_Charge | Sum_Gold_Duration | Sum_Gold_Charge | Sum_Silver_Duration | Sum_Silver_Charge
    01/01/2011 | A | 9. 10. 5. 2. 4. 8
    01/01/2011 | B | 10. 10. 10. 10. 0 | 0
    01/01/2011 | C | 4. 11. 0 | 0 | 4. 11
    01/01/2011 | D | 2. 4. 2. 4. 0 | 0

    This query will provide the 1st four columns:

    SELECT Date1,
    base1,
    Sum (Duration) Sum_Duration,
    Sum (load) Sum_Charge
    FROM TABLE_A
    GROUP BY date1, rarateplan

    But I need to know how to get the rest of the columns (i.e. Summary according to categories; from 5 to 8 columns)? Is this can be done in a single query without writing subqueries?

    Please let me know, (with code), the best way.

    Thank you-
    Tanvir

    Use like this:

    SELECT Date1,
    base1,
    Sum (Duration) Sum_Duration,
    Sum (load) Sum_Charge,
    SUM (decode(Category,'Gold',duration,0)) Sum_Gold_Duration,
    SUM (decode(Category,'Gold',charge,0)) Sum_Gold_charge,
    SUM (decode(Category,'Silver',duration,0)) Sum_Silver_Duration,
    SUM (decode(Category,'Silver',charge,0)) Sum_Silver_charge
    FROM TABLE_A
    GROUP BY date1, rarateplan

    Published by: SANT007 on August 11, 2011 11:04

  • The simple query help

    Hello! I have a simple request: NO of ROAD_TYPE = "RAMP" or NO FUNC_CODE = 7 FUNC_CODE or NOT = 0 or NOT FUNC_CODE = NULL, each element of the query by itself without problem, tracks, but linked together in this way with the GOLD, one of them opts on. What I am doing wrong?

    It's the difference between OR and and.

    Think about this simple example

    Where Column != A or Column != B.
    

    Excluding the Null handling, it's true. Because for the first condition, it will be true for all but one, and the second condition will be true for A. You need an AND, not a RC.

    For simplicity and readability without doubt, use an In operator, and group together them. It would therefore be:

    Where Road_Type != 'RAMP' and Func_Code Not In('0, 7) and Func_Code is not Null
    
  • Decode the simple function

    Gurus,

    Please help me with a decoding function.

    doknlbc can be null or different bnuinfc in some occasions.

    Select dokkeyi, (doknlbc, null, 'no emp_id', bnuinfc) decoding as dok emp_id, bnu
    where doknlbc = bnunamc and dokkeyi in (6545,6525);


    Result
    EMP_ID DOKKEYI
    6545 70348

    Result, I want to!
    EMP_ID DOKKEYI
    6545 70348
    6525 no emp_id

    Thanks for the help!

    Try this:

    select dokkeyi, decode(doknlbc,null,'no emp_id',bnuinfc) as emp_id
    from dok, bnu
    where
         ( doknlbc = bnunamc  or
           doknlbc is null
         )
         and dokkeyi in (6545,6525);
    
  • decode the simple question

    I had a table called customer_issue_tab that has a column called 'IS_AUTH '.
    If the value of 'IS_AUTH' is true then I should show the line else I need to check the State of the 'CUST_ORDER_TAB' and if the status = 'released' then display the line.

    How can I put these in a select stmt using a DECODING function

    code example would be ideal

    Thank you

    Parsh

    Published by: [email protected] on July 6, 2009 09:28

    Hello

    The answer to "" How do I... using DECODE? ". is always "do not DECODE." If you have to ask, then it's too complicated.
    CASE is the most common to DECODE alternative.

    If you want to use the results in a WHERE clause, why not use the conditions in a WHERE clause, without DECODING?
    Something like that, maybe:
    {code}
    WHERE is_auth = 'TRUE '.
    THERE ARE (SELECT 1 OR)
    OF cust_order_tab
    Situation WHERE = 'product '.
    AND order_no = customer_issue_tab.order_no
    )
    {code}
    If you need help, post a small example of data and the results desired from these data.

  • Helps the simple query XPath in OSB

    Hello!

    I try to extract a part of XML with Oracle Service Bus using XPath message, but I can't find the way to make

    For testing purposes, I initialize a variable 'test' with an action of assignment with the following content:

    < Country > < country > < COUNTRY > ARE < / COUNTRIES > < S EU_COUNTRY > < / EU_COUNTRY > < Spain NUMBER > < / NUMBER > < ID > 1 < /ID > < country > < / country >

    Can I use following code to access the COUNTRY element but I get blank result:

    $test, Countries, Country, COUNTRY / text)

    I'm rather new to XPath, but I think that this expression should work.

    Could someone give me some advice?

    Thank you.

    Published by: user542345 on June 15, 2011 09:06

    Use

    $test / country/COUNTRY/text)

  • Functions in the inner query

    Hello!
    I challenged the following problem. Here's the simple query:

    SELECT id, id, id from
    (select 1, sys_guid () as double id)

    as you can see there is a sys_guid() function in the inner query. So, why do we use these
    constructions? Right - to calculate the value of a function once and use it again so much
    time, that we need. So I guess to get three identical fields. But, as it turns out, it is not
    always too! I mean, on one version of Oracle database this query return the same three
    fields, but on another - three different! Based on what the sys_guid() function is a kind of
    random function, I can assume that the function is run three times in the second case
    instead of one (as it should)! So why is it? Is - this bug from version, or an option in
    control file that influence the optimizer?

    PS: I found a workaround on this basis, where this query produces abnormal results, we can use
    Internal ORDER BY clause in the query:

    SELECT id, id, id from
    (select 1, sys_guid () as command id double by 1)

    The oracle optimizer is the fusion view inline with the outer select block. He replaced effectively by:

    select sys_guid(), sys_guid(), sys_guid()
    from dual
    

    You can avoid this as follows:

    select /*+ no_merge(x) */
             id,id,id from
    (select 1,sys_guid() as id from dual) x
    

    Published by: Toon Koppelaars on July 9, 2009 09:22

  • Use the DECODE and RIGHTEOUS in the sql query

    Friends...

    Could someone help with DECODE and sql RIGHT or similar function?

    I'm doing below in the SQL query

    1. DECODE any process with s.process = 1234 to replace with JAVA
    2. RIGHT: Removes all characters after ' @' sign

    SQL query:

    SELECT s.osuser, s.machine, DECODE(s.process, '1234', 'JAVA', right(s.process,charindex('@',s.process)-1)) s.process FROM v$session; 

    for example

    EXAMPLES of data

    User, machine, process

    John, mac1, 1234

    Mike, mac2, 567@mac2

    Julie, mac3, 890


    The result of the SAMPLE:

    User, machine, process

    John, mac1, JAVA

    Mike, mac2, 567

    Julie, mac3, 890

    Thanks in advance

    Thanks guys... I am overwhelmed with all these answers and support on this forum, I received...

    I have combined Solomon and Frank response to achieve accurate result...

    with the answers of Solomon he displayed empty process when there is ' @' sign

    Frank's response showed it process with sign @ the end... so I added '-1' in the end.ยป

    SELECT s.osuser,

    s.machine,

    DECODE)

    s.Process,

    "1234", "JAVA",

    substr)

    s.Process,

    1,

    InStr)

    s.Process | '@',

    '@'

    ) - 1

    )

    ) process

    V $ session s

    /

  • Choice of the message can be changed in the table of search results Simple query region?

    Hi friends,

    I have a Simple search query region in 11i.

    I created the SearchVO and bound to the query Table Region.

    I have two attributes MessageStyleText and a MessageChoice attribute in the simple search criteria.

    Search results show very well for all attributes.

    But when I search with the criteria of MessageChoice, in the table of results, this attribute MessageChoice is indicated as editable, display the drop-down list.

    I did this attribute ReadOnly = True but then it becomes readonly in search also. So this dosent help.

    I need to this drop-down list of MessageChoice be modifiable in the search criteria, but read in the table of results.

    Please help me with the resolution. Its kinda urgent.

    Would appreciate any help.

    Thank you

    Rajesh

    He solved.

    Added programmatically in code.

    Kept the attribute as MessageChoice in the query Table Region.

    Added to the controller

    ' Public Sub processRequest (pageContext OAPageContext, OAWebBean webBean)

    {

    super.processRequest (pageContext, webBean);

    OAM OAApplicationModule = pageContext.getRootApplicationModule ();

    OAMessageChoiceBean = processFlagMessageChoice

    (OAMessageChoiceBean) webBean.findChildRecursive ("AttributeId");

    processFlagMessageChoice.setReadOnly (true);

    }

  • Decode the query help

    Hello
    I'm new to the development of Oracle.
    Oracle 10 g 2

    My original query:

    SELECT APP, count (*)
    TRANSACTION
    WHERE TYPE in ('ShipmentConfirmPR', 'ShipmentConfirm', 'ShipConfirm')
    and the APP ("SAPPI", "SAPPI", "SAPR3") and INTERVENE ('9320 ', '9332','1208 ')
    GROUP BY APP TYPE
    order of the APP

    the result of this query:
    SAPPI 100
    SAPPI 600
    SAPR3 440

    My requirement
    And I want to have something like output

    LDCS 100
    TSW 600
    PDC 440

    IE.the APPP and STEP combinations. Must return the specified values
    SAPPI & 9320-> LOC (here SAPPI IE APP is the same for both... but it's a coincidence IE APP can be sliced also)
    SAPPI & 9332-> tsw
    SAPR3 & 1208-> pdc

    Options, I tried:
    Query provided by one of the Forum members...
    SELECT THE CHECK BOX
    WHEN APP = "SAPP1" THEN DECODE (step, '9320', 'LSW', '9332', "TSW")
    WHEN APP = "SAPR3" step = '1208' AND 'PDC '.
    END app
    COUNT (*)
    TRANSACTION
    WHERE TYPE in ('ShipmentConfirmPR', 'ShipmentConfirm', 'ShipConfirm')
    AND THE APP ("SAPPI", "SAPPI", "SAPR3")
    AND STEP IN ('9320', '9332', ' 1208')
    GROUP BY APP, STEP
    ORDER OF THE APP.

    EXECUTION PLAN

    | ID | Operation | Name |
    ------------------------------------------------------------------------
    | 0 | SELECT STATEMENT |
    | 1. GROUP SORT BY |
    | 2. INLIST ITERATOR.
    | 3. TABLE ACCESS BY INDEX ROWID | TRANSACTION |
    | 4. INDEX RANGE SCAN | TRANSACTION_IDX |


    The output of the query (as above) must partially match the following query (a particular combination of CLO)

    SELECT count (1)
    TIBCO. TRANSACTION_HISTORY
    WHERE TYPE = 'ShipmentConfirm '.
    and APP in ("SAPPI") and INTERVENE ('9332')


    My Questions:

    1.*There are indexes on all 3 APP passes it's IE, STEP and TYPE *. I don't want a FULL table Scan (as one would use the index). Can change us the query / use of indices, etc. to make it faster?

    2. is the right to approach? Would the use of the concat operator in the function decode work better for my needs?
    Something like

    Select decode (APP |) STEP, 'SAPP9332', 'X') of TRANSACTION_HISTORY where < COND >

    If Yes can you please provide the query?

    3. ANY other approach / request for my requirement.

    Thanks in advance.

    Hello

    user13517642 wrote:
    ... EXECUTION PLAN

    | ID | Operation | Name |
    ------------------------------------------------------------------------
    | 0 | SELECT STATEMENT |
    | 1. GROUP SORT BY |
    | 2. INLIST ITERATOR.
    | 3. TABLE ACCESS BY INDEX ROWID | TRANSACTION |
    | 4. INDEX RANGE SCAN | TRANSACTION_IDX |

    The output of the query (as above) must partially match the following query (a particular combination of CLO)

    SELECT count (1)
    TIBCO. TRANSACTION_HISTORY
    WHERE TYPE = 'ShipmentConfirm '.
    and APP in ("SAPPI") and INTERVENE ('9332')

    My Questions:

    1.*There are indexes on all 3 APP passes it's IE, STEP and TYPE *. I don't want a FULL table Scan (as one would use the index). Can change us the query / use of indices, etc. to make it faster?

    A full table scan might be the fastest way to get results. Do you have any reason to think that it would be faster to go through the index? How selective are the clues? In other words, what is the percentage of rows in the table correspond to each of the values in the WHERE clause?

    2. is the right to approach?

    It depends on what you're trying to do, which is not at all clear to me.

    Would the use of the concat operator in the function decode work better for my needs?
    Something like

    Select decode (APP |) STEP, 'SAPP9332', 'X') of TRANSACTION_HISTORY where

    If you use this approach, look out for the problem Ab asse crevit . For example, if you have these 4 rows and 2 columns:

    str1     str2
    ----     ----
    (NULL)     FOO
    F     OO
    FO     O
    FOO     (NULL)
    

    There are 4 values of distict of str1 (counting NULL) and 4 separate values of str2, str1 but | str2 is the same for each of them. In the above example, it there is no way to know, just by looking at the concatenated string, including str1 and str2 ends begins. Maybe it's not the case for your specific data (for example, if the application is still exactly 5 characters long). otherwise, you may need to add some kind of delimiter, like this

    app || '+' || step
    

    where you know that '+' never occurs in one of these columns.

    3. ANY other approach / request for my requirement.

    CASES, as I mentioned in your previous message:
    Decode the help function
    and as you have used above.

    In this thread, you said "I have to use the decode function. Why? It is a competition of school Etudieeo DECODE is explicitly required? Why you don't want in the best way, what that turns out to be?

    Your WHERE clause:

    AND APP IN ('SAPPI', 'SAPPI', 'SAPR3')
    AND STEP IN ('9320', '9332', '1208')
    

    admits 6 possible combinations of APA and step:

    app     step
    -----     ----
    SAPP1     9320
    SAPP1     9332
    SAPP1     1208
    SAPP3     9320
    SAPP3     9332
    SAPP3     1208
    

    but you are looking for only 3 of these combinations in DECODE it or the expression BOX. (Have 2 copies of 'SAPP1' e list won't do any good, but it does hurt real, either.)
    By the way, is "SAPPI" app with the letter 'I' at the end, or "SAPP1", with the number '1' at the end?

    Published by: Frank Kulash, March 24, 2011 19:44

  • Simple query with a subquery returns the result of 'bad '.

    DB version: 11.2

    We have created approximately 27 patterns in the last 4 days. The query below confirms that.
    SQL > select username, created from dba_users where created > sysdate-4;
    
    USERNAME                       CREATED
    ------------------------------ --------------------
    MANHSMPTOM_DEV_01              12 Jul 2012 11:55:16
    PRSM01_OAT_IAU                 13 Jul 2012 01:51:03
    F_SW                           11 Jul 2012 17:52:42
    FUN_CDD_HK_SIT                 09 Jul 2012 15:33:57
    CEMSCOMPTOM_UAT_01             12 Jul 2012 11:43:45
    STORM02_OAT_IAU                13 Jul 2012 02:06:29
    .
    .
    27 rows selected.  -------------> Truncated output
    DBA_TS_QUOTAS.max_bytes column, we can determine the quota of space allocated for a user/schema
    SQL > desc dba_ts_quotas
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     TABLESPACE_NAME                           NOT NULL VARCHAR2(30)
     USERNAME                                  NOT NULL VARCHAR2(30)
     BYTES                                              NUMBER
     MAX_BYTES                                          NUMBER
     BLOCKS                                             NUMBER
     MAX_BLOCKS                                         NUMBER
     DROPPED                                            VARCHAR2(3)
    So, I wanted to see the space allocated for users created in the last 4 days. The following query should return only 27 cases because the subquery returns only 27 records. Instead, he returned 66 entries!
    select username, tablespace_name, max_bytes/1024/1024 quotaInMB
    from dba_ts_quotas
    where username in (select username from dba_users where created > sysdate-4);
    No idea why? I know this isn't a bug with oracle. It's just that I didn't eat fish lately.

    Hello

    J.Kiechle wrote:
    So, I wanted to see the space allocated for users created in the last 4 days.

    DBA_TS_QUOTAS does not have the space, but rather the maximum allowed for a given user.

    J.Kiechle wrote:
    The following query should return only 27 cases because the subquery returns only 27 records. Instead, he returned 66 entries!

    What happens if your user John has Quotas on 3 tablespace TBS1 and TBS3 and TBS2?
    You can't expect the outer query to retrieve only the more than 27 just line because the inner query returns 27 rows.

    For the space allocated by the storage space for newly created users, you'd better ask dba_segments. something like:

    select owner, tablespace_name, trunc(sum(bytes)/1024/1024) alloc_mb
    from dba_segments
    where owner in (select username from dba_users where created > sysdate - 4)
    group by owner, tablespace_name
    order by owner, tablespace_name;
    
  • How to call the &lt; af:query &gt; Search feature by clicking on an image?

    Hi all

    I created a test named and I dragged on my page .jspx as "ADF with Table query Panel. I put the display as 'Simple' Mode in the Properties Inspector, who will hide all the default components of < af:query >. Now I use < af:commandImageLink >. My question is how can I call the < af:query > Search feature when the user clicks on an image? Any suggestion would be appreciated.

    Thank U...

    If you want to invoke af:query search by program button, follow these steps:

    1 Select af:query--> Advanced--> connections and bind it to the back bean

      
    

    2. in the .jspx add af:link like this:

    
              
    
    

    3 - runQuerySearchAction should be like this:

      public String runQuerySearchAction()
      {
        QueryDescriptor queryDescriptor = getRichQuery().getValue();
        QueryEvent queryEvent = new QueryEvent(getRichQuery(), queryDescriptor);
        queryEvent.setPhaseId(PhaseId.INVOKE_APPLICATION);
        getRichQuery().queueEvent(queryEvent);
        return null;
      }
    
  • How to exclude records from the outer query

    My apologies if this was requested. I find no answer. I don't know what terminology should be for that matter.

    In simple terms, I want to use the custom in where clause to select records. Problem is function will fail if applied to old records, as there was no relevant data. I have logic to exclude old records, but the problem is that this process running function before old records are excluded. I tried an inside view to exclude records before their passage in the outer query, but this does not resolve the situation.

    Below shows high level required

    Select x

    tab

    where (condition to exclude the old records)

    and function (tab.y) = value

    If I rewrite as below, still have the problem. Was hoping to exclude former records apply before function.

    Select inn.x

    Of

    (select x,

    There

    tab

    where (condition to exclude the old records)) inn

    where function (inn.y) = value

    Thank you

    Hello

    Including ROWNUM in the result set of the query-void will force the subquery to do first:

    Select inn.x

    Of

    (select x,

    There,

    ROWNUM AS r

    tab

    where (condition to exclude the old records)

    ) inn

    where the function (inn.y) = some_value

    Since ROWNUM depends on the WHERE clause of the query-sup, the query cannot be rewritten to the main to do first query WHERE clause.

Maybe you are looking for