Join inner & outer join in a query

I have 11 paintings, 10 tables need will always be a match on the id, table 11 may or my not have a football game. I need to print information from the 10 tables with a matching id and the information in the table 11 if a record is found.

Help, please.

There is nothing wrong with having 10 inner joins and 1 outer join.

The syntax might look like this ANSII shaped:

Of

1Table INNER JOIN

2table ON (1Table.key = 2Table.KEY) JOIN IN-HOUSE

3Table ON (1Table.key = 3Table.KEY) JOIN IN-HOUSE

4Table ON (1TAble.key = 4Table.key) JOIN IN-HOUSE

INNER JOIN 5Tableau ON (1Table.key = 5table.key)

6Table ON (1Table.key = 6table.key) JOIN IN-HOUSE

INNER JOIN 7Table ON (1Table.key = 7Table.key)

8Table ON (1Table.key = 8Table.key) JOIN IN-HOUSE

INNER JOIN 9Table ON (1Table.key = 9Table.key)

10Table ON (1Table.key = 10Tablekey) LEFT OUTER JOIN

11Table ON (1Table.key = 11Table.key)

You can use paretheses more group the results if you wish.

When you create a relationship of this process the best resort is to do a table at the same time.

Build the query to return properly the expected effect of the first table.  Then add the second and confirm that it is always the desired results.  Continue to add the tables one at a time, stable all along the way.

Tags: ColdFusion

Similar Questions

  • How to specify an outer join in the query designer

    I quickly built a large query with the query designer, and it works very well, but does not produce 9 disks on 2200 - so I need to change to an outer join.

    My problem is that I can't find a way to specify an outer join. I tried to change the query, query builder formed, but it won't let me.

    I know that I can capture the query, edit and run it in sql developer and that works fine, but I want to use the Query Builder as it is the fastest way I know to quickly add and remove items - my users don't know exactly what that it to include.

    I know it's kind of a trivial question, but I searched the forum, manual, the web and no luck

    Thanks for any help you can give

    Glenn

    Hi Glenn,.

    When you use the query designer to create the sql statement, you must click on the empty box to the right of the fields in each table to create the join. When you are finished, you should see a line drawn between the two tables. Click on this line, and a small window appears allowing you to select inner outer or right outer joins, left.

    When the report was created, however, you must change the statement. For example, if you use the query designer to join DEPT at EMP based on the DEPTNO field on the two tables, you get:

    select      "DEPT"."DEPTNO" as "DEPTNO",
          "DEPT"."DNAME" as "DNAME",
          "DEPT"."LOC" as "LOC",
          "EMP"."EMPNO" as "EMPNO",
          "EMP"."ENAME" as "ENAME",
          "EMP"."JOB" as "JOB",
          "EMP"."MGR" as "MGR",
          "EMP"."HIREDATE" as "HIREDATE"
     from      "EMP" "EMP",
          "DEPT" "DEPT"
     where   "DEPT"."DEPTNO"="EMP"."DEPTNO"
    

    This is to change:

    select      "DEPT"."DEPTNO" as "DEPTNO",
          "DEPT"."DNAME" as "DNAME",
          "DEPT"."LOC" as "LOC",
          "EMP"."EMPNO" as "EMPNO",
          "EMP"."ENAME" as "ENAME",
          "EMP"."JOB" as "JOB",
          "EMP"."MGR" as "MGR",
          "EMP"."HIREDATE" as "HIREDATE"
     from      "EMP" "EMP"
          LEFT OUTER JOIN "DEPT" "DEPT" ON "DEPT"."DEPTNO"="EMP"."DEPTNO"
    

    Andy

  • LEFT OUTER JOIN, trigger after QUERY problem

    Hello

    Guide to please the following

    I wrote under query in QUERY after a BLOCK of TABULAR DATA, not as a single text element, called INVENTORY_ITEM

    Select c.cat |' '|| s.SubCat |' '|| L1.lvl1 POINT IN: DATABLOCK. INVENTORY_ITEM
    of itemcat c
    LEFT OUTER JOIN itemsubcat s on (c.catid = s.catid)
    LEFT OUTER JOIN lvl1 l1 on (s.subcatid = l1.subcatid)

    When I compile the module an error is generated

    «* ' Met the 'LEFT' symbol when waiting for one of the following values for the group with intersect less order start union where connect '.» *

    Top query works fine with ORACLE SQL DEVELOPER.

    Any solution please.

    Kind regards

    Difference

  • Case Based Condition of inner join in SQL query

    Hi Experts,
    CREATE TABLE PRODUCT_PRICE(PRODUCT_ID INTEGER,PRICE FLOAT);
    INSERT INTO PRODUCT_PRICE VALUES(1,1);
    INSERT INTO PRODUCT_PRICE VALUES(2,2);
    INSERT INTO PRODUCT_PRICE VALUES(3,1);
    INSERT INTO PRODUCT_PRICE VALUES(4,1);
    INSERT INTO PRODUCT_PRICE VALUES(5,3);
    INSERT INTO PRODUCT_PRICE VALUES(0,4);
    CREATE TABLE PRODUCT_TABLE (PRODUCTID INTEGER,OTHERID INTEGER);
    INSERT INTO PRODUCT_TABLE VALUES (1,0);
    INSERT INTO PRODUCT_TABLE VALUES (2,0);
    INSERT INTO PRODUCT_TABLE VALUES (3,1);
    INSERT INTO PRODUCT_TABLE VALUES (4,1);
    INSERT INTO PRODUCT_TABLE VALUES (5,2);
    I need to match the product_id = 0 to get the price of the product when there is othersid in the product table (otherid > 0). For this I created the query below.
    SELECT 
        PRODUCT_ID,
        PRICE 
    FROM 
        PRODUCT_TABLE
        INNER JOIN PRODUCT_PRICE ON PRODUCT_ID=PRODUCTID
    WHERE
        OTHERID=0
    UNION ALL
    SELECT 
        PRODUCT_ID,
        PRICE 
    FROM 
        PRODUCT_TABLE
        INNER JOIN PRODUCT_PRICE ON PRODUCT_ID=0
    WHERE
        OTHERID>0;
    My Question is, is that any way the SQLQuery above can be simplified in CASES and INTERNAL CONDITION JOIN in a single SQL QUERY?

    I can work around something like that,
    SELECT 
        PRODUCT_ID,
        PRICE 
    FROM 
        PRODUCT_TABLE
        INNER JOIN PRODUCT_PRICE ON * CASE WHEN OTHERID>0 THEN PRODUCT_ID=0 ELSE PRODUCT_ID=PRODUCTID END*
    Thank you
    SELECT CASE WHEN PT.OTHERID = 0 THEN PT.PRODUCTID ELSE 0 END AS PRODUCT_ID, PP.PRICE
      FROM PRODUCT_TABLE PT,  PRODUCT_PRICE PP
        WHERE CASE WHEN PT.OTHERID =0 THEN PT.PRODUCTID ELSE 0 END = PP.PRODUCT_ID
    

    Should it?

  • Join in a query

    Hello!

    I am neawby in SQL, and I have some problems with a request...

    I have a table called 'Artist' like this:
    ART_ID     ART_NAME         ART_DESCRIPTION
    1          Artist1          Desc1
    2          Artist2          Desc2
    3          Artist3          Desc3
    4          Artist4          Desc4
    And another table called 'Tour' like this:
    TOUR_ID   TOUR_DATE          TOUR_ART_ID
    1         10/10/2013         1
    2         14/07/2014         4
    And finally, I want to show something like this:
    ART_ID     ART_NAME         ART_DESCRIPTION         TOUR_DATE
    1          Artist1          Desc1                   10/10/2013
    2          Artist2          Desc2
    3          Artist3          Desc3
    4          Artist4          Desc4                   14/07/2014
    If no tour_date for this artist, I want to show the artist too.

    Thanks in advance!

    Try this:

    select art_id, art_name, art_description, tour_date
    from   artist
           left outer join tour on (art.art_id = tour.tour_art_id)
    
  • join in the query

    Hello world

    My question today is 'can we join two queries.


    Select the name of database v$.

    Select bytes/1024/1024/1024, count (segment_name) in dba_segments where nom_segment = 'tablename ';


    could you guys please help me on with this one as well

    I actually want my output to be something like below

    Name byte count (segments_name)
    -------------------------------------------------------------------------
    1800 27 DB


    Concerning
    Shareef

    SELECT (select v$ v database name $) db,.
    Select bytes/1024/1024/1024, count (segment_name) in dba_segments where nom_segment = 'tablename ';

  • join in the query with the result of a single line

    Hi all

    I have two tables
    create table item(item_id number primary key,
    item_desc varchar2(200));
    
    create table item_properties(item_id number references item(item_id),
    property_name varchar2(20),
    property_value varchar2(100));
    I insert the following records
    insert into items values(1,'CPU');
    insert into item_properties values(1,'RAM','2gb');
    insert into item_properties values(1,'PROCESSOR','2ghz');
    insert into item_properties values(1,'HARDDISK','2ghz');
    commit;
    now I want a query that produces the following results
    item_id      RAM      PROCESSOR         HARDDISK
    1              2gb        2ghz              2TB
    How to generate this result?
    I create a query, but it generates several lines, instead I need a single line like above.
    select i.item_id,p.property_value from items i , item_properties p
    where i.item_id=p.item_id and i.item_id=1;
    Kind thanks.

    Published by: Maahjoor on May 7, 2013 12:22 AM
    select i.item_id,
           max(decode(p.property_name,'RAM',p.property_value)) ram,
           max(decode(p.property_name,'PROCESSOR',p.property_value)) processor,
           max(decode(p.property_name,'HARDDISK',p.property_value)) hd
    from items i , item_properties p
    where i.item_id=p.item_id
    and i.item_id=1
    group by i.item_id;
    

    Or pivot to 11g

    with details as
    (
    select i.item_id,p.property_name,p.property_value
    from item i , item_properties p
    where i.item_id=p.item_id
    and i.item_id=1
    )
    select *
    from details
    pivot
     (
       max(property_value) for property_name in ('RAM','PROCESSOR','HARDISK')
     );
    

    Published by: JAC on May 7, 2013 13:04

  • Kindly help for mentioning out with an SQL query, thanks

    Hello

    Please find below the input grid and help me get the result. Thanks in advance.  [Seeks assistance of query tunned]

    with the temp as

    (select alert_id 100, 111 double branch_code)

    Union of all the

    Select double 100 111

    Union of all the

    Select double 100 222

    Union of all the

    Select double 101 333

    Union of all the

    Select double 101 444

    Union of all the

    Select double 101 555

    Union of all the

    Select double 102 666

    Union of all the

    Select double 102 666

    Union of all the

    Select 102 666 double)

    Select * Temp;

    Entry
    Alert_IDBranch_code
    100111
    100111
    100222
    101333
    101444
    101555
    102666
    102666
    102666

    Output
    Alert_idBranch_code
    100111 222
    101333,444,555
    102666

    Thanks a ton

    Arpit

    Oracle 11 g 2, with analysis of the table only once. .. Here's how:

    WITH temp1

    AS (SELECT alert_id,

    branch_code,

    ROW_NUMBER)

    COURSES (PARTITION BY alert_id ORDER BY branch_code)

    DSB

    TEMP

    GROUP BY alert_id, branch_code)

    SELECT alert_id,

    LISTAGG (branch_code, ",") WITHIN GROUP (ORDER BY DSB) branch_code

    OF temp1

    GROUP BY alert_id;

    ALERT_ID BRANCH_CODE

    100 111 222

    101 333,444,555

    102 666

    See you soon,.

    Manik.

  • How create/update files when the original Version is based on a query of outer join?

    Hi gurus,


    I created a custom page where I use a table-style area where I question my VO records, based on a query of outer join. This query contains my table looks, where I would like to insert/update records, and joined the table of standard elements, which is external with my custom table.

    When I now question my files in the t, I have a record for each record in the table section, which is ok, but when I 'Refresh' some fields of my custom table and attempt to commit, I get the message "unable to complete the transaction on record. Cause: The record has been deleted by another user. "Action: cancel the transaction and re - query records to get new data.
    The reason why because a record is to be inserted rather than updating because in fact there is not yet in my custom table.

    The reason why I'm using the outer join, is because I don't want the user to create a record for each item one by one.
    There is no work around for this?

    Thanks in advance!


    BR
    Guy

    Hello
    You can try this.

    In your EntityImpl.java to extend OAPlsqlEntityImpl.

    Override the updateRow() method and coding your insert statement to insert into a table custom here.
    Don't forget, you must ignore the lines for which your custom table columns are null

    -Idris

  • Query of queries: error when you try to fake Left Outer Join

    Hello

    I'm trying to reproduce a left outer join, combining two query of queries using a method I find here

    However, I get an error message...

    Here is the code I use...

    < cfquery dbtype = "query" name = "qry" >
    SELECT *.
    OF returnQry, returnQry2
    WHERE returnQry.mediumImage = returnQry2.mediumImage
    ORDER BY returnQry.name
    < / cfquery >

    < name cfquery = "returnQry3", dbtype = "#application.mx #" >
    SELECT *.
    OF trackmeanings t
    < / cfquery >

    < cfquery dbtype = "query" name = "endQry" >
    SELECT name, nameRcd, mediumImage, comments COUNT (sMessage)
    OF qry, returnQry3
    WHERE qry.name = returnQry3.sNameTrack

    UNION

    SELECT name, nameRcd, mediumImage, comments COUNT (sMessage)
    OF qry, returnQry3
    WHERE #qry.name # NOT IN (#QuotedValueList (returnQry3.sNameTrack) #)
    GROUP BY name, nameRcd, mediumImage
    < / cfquery >

    When I try to use the query output in a page, I get the error message "incorrect conditional expression, waiting for an a [as |]» null | between | in | "comparison condition.

    Anyone have any ideas?

    Thank you very much

    The items in the list should be cited.  Since you are using quotedvaluelist, it's weird that they aren't.  However, if you use cfqueryparam, list = Yes, you should have better luck.  Among other things, it will protect you against the apostrophe in names.

  • difference between Inner Join join natural r

    Experts,

    I'm trying to understand the difference between Natural Join and inner join.

    Inner join: the following query provides 106 lines based on two tables

    SQL > SELECT EMPLOYEE_ID EID, last NAME, DEPT_NAME DEPARTMENT_NAME

    2 EMPLOYEES A, B MINISTRIES

    3. WHERE A.DEPARTMENT_ID = B.DEPARTMENT_ID

    4 order employee_id;

    Natural Join: This is the combination or combined result of all the columns in both tables.

    When I run the Sub statement, it combines employees and the table from department of a HR schema and provides only 32 ranks

    SQL > select employe_id, first_name, department_name

    2 departments of NATURAL JOIN employees;


    EMPLOYEE_ID NAME DEPARTMENT_NAME

    ----------- -------------------- -------------------

    Neena 101 Executive

    Lex 102 Executive

    104 Bruce IT

    David 105 HE

    question: why the NATURAL JOIN query omit the employee_id 103 and on what basis it omit a few other employee_id

    Thanks in advance

    Hello

    The main difference is that INNER JOIN is used in real life; NATURAL JOIN is used only in textbooks.

    More rigorously, FRANCKLIN JOIN is an inner join, involving all the columns that have the same name.  The hr.departments and hr.employees have 2 columns with the same name: department_id and manager_id, so

    OF hr.departments d

    NATURAL JOIN e hr.employees

    is equivalent to

    OF hr.departments d

    INNER JOIN hr.employees e ON e.department_id = d.deparment_id

    AND e.manager_id = d.manager_id

    or, using the old join syntax

    OF hr.departments d

    e hr.employees

    WHERE e.department_id = d.deparment_id

    AND e.manager_id = d.manager_id

  • Join query with union

    Hi all

    I have two requests and I want to join this two query

    The column of the report should be like this
    item_number WK_30  WE_31
    1st request
    select 
    re.item_number, 
    nvl(le.quantity,0) - nvl(re.quantity,0) WK_30
    from BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re
    where le.item_number =re.item_number
    and to_number(substr(re.year_week,-2,2)) = to_number(to_char(sysdate,'IW'))+1
    2nd request
    select 
    re.item_number, 
    nvl(le.quantity,0) - nvl(re.quantity,0) WK_31
    from BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re
    where le.item_number =re.item_number
    and to_number(substr(re.year_week,-2,2)) = to_number(to_char(sysdate,'IW'))+2
    Thanks in advance

    Concerning

    Hello

    You are welcome.

    I think that the best way to understand that is to show what data is generated at each stage...

    1. we need to generate a list of lines that have every week, we are interested in swing on...

    (   SELECT
            to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num
        FROM
            DUAL
        CONNECT BY LEVEL <= 5
    ) row_gen
    
    YEAR_WEEK_NUM
    -------------
               30
               31
               32
               33
               34
    

    2. must be added BACKLOG_WEEK_WH_AFTR_ATP lines in the calculations for the first week in the report

    SELECT
        le.item_number,
        le.quantity,
        to_number(to_char(sysdate,'IW'))+1 year_week_num
    FROM
        BACKLOG_WEEK_WH_AFTR_ATP le
    UNION ALL
    SELECT
        re.item_number,
        -re.quantity,
        to_number(substr(re.year_week,-2,2)) year_week_num
    FROM
        BACKLOG_ATP_GT_CW_IN re
    /
    ITEM_NUMBE   QUANTITY YEAR_WEEK_NUM
    ---------- ---------- -------------
    ITEM_1            200            30
    ITEM_2            600            30
    ITEM_1           -200            30
    ITEM_1           -100            33
    ITEM_2           -300            30
    ITEM_2           -200            32
    ITEM_3           -800            30
    ITEM_3           -400            34
    

    3. we must now repeat weekly, generated by the request of row_gen against all of the item_numbers returned by the above query and match them if possible to get the amount. Where there is no entry in BACKLOG_WEEK_WH_AFTR_ATP or BACKLOG_ATP_GT_CW_IN for a number of the week, we should use 0 as the quantity. The Partition Outer Join does for us.

    SQL>         select
      2              re.item_number,
      3              row_gen.year_week_num,
      4              NVL(re.quantity,0) qty
      5          from
      6              (   SELECT
      7                      to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num
      8                  FROM
      9                      DUAL
     10                  CONNECT BY LEVEL <= 5
     11              ) row_gen LEFT OUTER JOIN
     12                      (   SELECT
     13                              le.item_number,
     14                              le.quantity,
     15                              to_number(to_char(sysdate,'IW'))+1 year_week_num
     16                          FROM
     17                              BACKLOG_WEEK_WH_AFTR_ATP le
     18                          UNION ALL
     19                          SELECT
     20                              re.item_number,
     21                              -re.quantity,
     22                              to_number(substr(re.year_week,-2,2)) year_week_num
     23                          FROM
     24                              BACKLOG_ATP_GT_CW_IN re
     25                       ) re
     26                  PARTITION BY (re.item_number)
     27                  ON ( row_gen.year_week_num = re.year_week_num)
     28  /
    
    ITEM_NUMBE YEAR_WEEK_NUM        QTY
    ---------- ------------- ----------
    ITEM_1                30        200
    ITEM_1                30       -200
    ITEM_1                31          0
    ITEM_1                32          0
    ITEM_1                33       -100
    ITEM_1                34          0
    ITEM_2                30       -300
    ITEM_2                30        600
    ITEM_2                31          0
    ITEM_2                32       -200
    ITEM_2                33          0
    ITEM_2                34          0
    ITEM_3                30       -800
    ITEM_3                31          0
    ITEM_3                32          0
    ITEM_3                33          0
    ITEM_3                34       -400
    
    17 rows selected.
    

    4. now, we have the base dataset that we need - she has all the amounts with the right directions so that we can simply add everything up as a sum of sumulative. That's what makes OVER(PARTITION BY re.item_number ORDER BY row_gen.year_week_num) SUM (NVL(re.quantity,0)) bit. He said baseically are all lines seen so far in the result set for each item number...

            select
                re.item_number,
                row_gen.year_week_num,
                NVL(re.quantity,0) qty,
                SUM(NVL(re.quantity,0)) OVER(PARTITION BY re.item_number ORDER BY row_gen.year_week_num) quantity
            from
                (   SELECT
                        to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num
                    FROM
                        DUAL
                    CONNECT BY LEVEL <= 5
                ) row_gen LEFT OUTER JOIN
                        (   SELECT
                                le.item_number,
                                le.quantity,
                                to_number(to_char(sysdate,'IW'))+1 year_week_num
                            FROM
                                BACKLOG_WEEK_WH_AFTR_ATP le
                            UNION ALL
                            SELECT
                                re.item_number,
                                -re.quantity,
                                to_number(substr(re.year_week,-2,2)) year_week_num
                            FROM
                                BACKLOG_ATP_GT_CW_IN re
                         ) re
                    PARTITION BY (re.item_number)
                    ON ( row_gen.year_week_num = re.year_week_num)
    /
    ITEM_NUMBE YEAR_WEEK_NUM        QTY   QUANTITY
    ---------- ------------- ---------- ----------
    ITEM_1                30        200          0
    ITEM_1                30       -200          0
    ITEM_1                31          0          0
    ITEM_1                32          0          0
    ITEM_1                33       -100       -100
    ITEM_1                34          0       -100
    ITEM_2                30       -300        300
    ITEM_2                30        600        300
    ITEM_2                31          0        300
    ITEM_2                32       -200        100
    ITEM_2                33          0        100
    ITEM_2                34          0        100
    ITEM_3                30       -800       -800
    ITEM_3                31          0       -800
    ITEM_3                32          0       -800
    ITEM_3                33          0       -800
    ITEM_3                34       -400      -1200
    

    5. we can now rotate these data in columns - however, there is a small problem. For points 1 and 2 we have 2 lines for the week 30, running in the quantity column total is the same for both because the two lines appear at the same point in the game as defined by the order by clause. This means before rotate us, we must select one of the lines - or the other will do, they are both correct. If we do not have, the effect will be to double the cumulative sum (for point 1 is 0, so it does not appear) for this, we can use the ROW_NUMBER function...

            select
                re.item_number,
                row_gen.year_week_num,
                NVL(re.quantity,0) qty,
                SUM(NVL(re.quantity,0)) OVER(PARTITION BY re.item_number ORDER BY row_gen.year_week_num) quantity,
                ROW_NUMBER() OVER(PARTITION BY re.item_number, row_gen.year_week_num ORDER BY NULL) rn
            from
                (   SELECT
                        to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num
                    FROM
                        DUAL
                    CONNECT BY LEVEL <= 5
                ) row_gen LEFT OUTER JOIN
                        (   SELECT
                                le.item_number,
                                le.quantity,
                                to_number(to_char(sysdate,'IW'))+1 year_week_num
                            FROM
                                BACKLOG_WEEK_WH_AFTR_ATP le
                            UNION ALL
                            SELECT
                                re.item_number,
                                -re.quantity,
                                to_number(substr(re.year_week,-2,2)) year_week_num
                            FROM
                                BACKLOG_ATP_GT_CW_IN re
                         ) re
                    PARTITION BY (re.item_number)
                    ON ( row_gen.year_week_num = re.year_week_num)
    /
    ITEM_NUMBE YEAR_WEEK_NUM        QTY   QUANTITY         RN
    ---------- ------------- ---------- ---------- ----------
    ITEM_1                30        200          0          1
    ITEM_1                30       -200          0          2
    ITEM_1                31          0          0          1
    ITEM_1                32          0          0          1
    ITEM_1                33       -100       -100          1
    ITEM_1                34          0       -100          1
    ITEM_2                30       -300        300          1
    ITEM_2                30        600        300          2
    ITEM_2                31          0        300          1
    ITEM_2                32       -200        100          1
    ITEM_2                33          0        100          1
    ITEM_2                34          0        100          1
    ITEM_3                30       -800       -800          1
    ITEM_3                31          0       -800          1
    ITEM_3                32          0       -800          1
    ITEM_3                33          0       -800          1
    ITEM_3                34       -400      -1200          1
    

    6. so now that we have a way to select one of the duplicate lines, we can move forward a pivot data by ensuring that us choose only 'first' line for each element for each week...

    SELECT
        item_number,
        SUM
        (   CASE
                WHEN year_week_num = to_number(to_char(sysdate,'IW'))+1 THEN
                    quantity
            END
        ) plus_1,
        SUM
        (   CASE
                WHEN year_week_num = to_number(to_char(sysdate,'IW'))+2 THEN
                    quantity
            END
        ) plus_2,
        SUM
        (   CASE
                WHEN year_week_num = to_number(to_char(sysdate,'IW'))+3 THEN
                    quantity
            END
        ) plus_3,
        SUM
        (   CASE
                WHEN year_week_num = to_number(to_char(sysdate,'IW'))+4 THEN
                    quantity
            END
        ) plus_4,
        SUM
        (   CASE
                WHEN year_week_num = to_number(to_char(sysdate,'IW'))+5 THEN
                    quantity
            END
        ) plus_5
    FROM
        (   select
                re.item_number,
                row_gen.year_week_num,
                SUM(NVL(re.quantity,0)) OVER(PARTITION BY re.item_number ORDER BY row_gen.year_week_num) quantity,
                ROW_NUMBER() OVER(PARTITION BY re.item_number, row_gen.year_week_num ORDER BY NULL) rn
            from
                (   SELECT
                        to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num
                    FROM
                        DUAL
                    CONNECT BY LEVEL <= 5
                ) row_gen LEFT OUTER JOIN
                        (   SELECT
                                le.item_number,
                                le.quantity,
                                to_number(to_char(sysdate,'IW'))+1 year_week_num
                            FROM
                                BACKLOG_WEEK_WH_AFTR_ATP le
                            UNION ALL
                            SELECT
                                re.item_number,
                                -re.quantity,
                                to_number(substr(re.year_week,-2,2)) year_week_num
                            FROM
                                BACKLOG_ATP_GT_CW_IN re
                         ) re
                    PARTITION BY (re.item_number)
                    ON ( row_gen.year_week_num = re.year_week_num)
        )
    WHERE
        rn = 1
    GROUP BY
        item_number
    

    You need not add a join between BACKLOG_WEEK_WH_AFTR_ATP and BACKLOG_ATP_GT_CW_IN, because we are all summed up in the article number and all item numbers, we have selected two tables. The aggregation ensures that the quantities are added together against the item number.

    HTH

    David

  • query using the JOIN

    Hello


    my appearance of the table structure:

    Column names:

    Road
    BU
    sub_bu
    report_order
    sub_bu_order
    q1py

    My query is:

    Select road, bu, Sub_bu, report_order, sub_bu_order, q1py, case
    When sub_bu = 'ISS' then (select q1py from STG where 'a.sub_bu =' ESS and a.rhead = b.rhead)
    When sub_bu = "TS" then (select q1py from STG where 'a.sub_bu =' Services and a.rhead = b.rhead)
    When sub_bu = "SW" then (select q1py from STG where a.sub_bu = 'SW' and a.rhead = b.rhead)
    otherwise NULL end as q1py_bu,
    case
    When sub_bu = 'ISS' then (select q1py from STG where a.sub_bu = 'TSG' and a.rhead = b.rhead)
    When sub_bu as 'R & D' and road in ('Region owned opex', '% of income', "opex Région", "Région opex %") then
    (select q1py from STG where a.sub_bu like 'STG' and a.rhead = b.rhead)
    ANY other purpose like STG q1py_tot b where report_order = 1

    Result:

    Bu road report_order sub_bu_order q1py q1py_bu q1py_tot sub_bu
    order ESS ISS 1162 1 1 1778,4 2953.9

    Here I use the sub query to produce the result. I need to give the same result by using JOINS.

    If someone help me, by using JOINS instead of QUERY SUB and produce the same result



    Thanks in advance

    Maybe you can use SQL as below. (B-)

    select Rhead,bu,Sub_bu,report_order,sub_bu_order,q1py,
    case
    when sub_bu='ISS'
    then max(case when sub_bu='ESS' then q1py end)
    over(partition by rhead)
    when sub_bu='TS'
    then max(case when sub_bu='Services' then q1py end)
    over(partition by rhead)
    when sub_bu='SW'
    then max(case when sub_bu='SW' then q1py end)
    over(partition by rhead)
    end as q1py_bu
    from tsg
     where report_order=1;
    
  • Select the list, joins

    HY!

    I have a list of selection with a query like this:

    select A._NAME as display_value,A._ID as return_value
      from A;
    

    Works fine of course.

    But I want to make this more dynamic list.

    I need to perform a join with another table, but it does not accept my request.

    It is not possible:

    select A._NAME as display_value, A._ID as return_value, A.AnotherIDWichINeedForAJoin
      from A;
    

    I get this error:

    Impossible to analyze the query SQL LOV!

    ORA-00904: "A". "" AnotherIDWichINeedForAJoin ": invalid identifier

    Is it not possible to make a join in a query select list?

    Is there another way to make a selection list that can manage the entry of a session (for example with a join) variable?

    Thanks for the help,

    ILB.

    It is possible to do a join, Yes, but in a query select list, you can have two values, a display and a return value, you have three, which will give an error. Always write and test your query in SQL or SQL Workshop first developer and make sure it works it before using it in the APEX, so you are sure that your request is correct.

  • Join ANSI join VS. Oracle (old join)

    Hello
    I have a request on the old version of join for oracle
    its not take more then 30 dry running, I tried to change to an ANSI join query
    but then he tooks 400 seconds, I would like to know how Oracle is to solve the two querys?
    Im running the application on a different server where the tables.

    These are the querys


    Qry 1 - old join
    Select cp.account_no,
    CPC.id_value Subscr_no,
    cce.Component_id,
    CCE.active_dt,
    CP. Package_instance_id_serv
    Of Cmf_Packages@arborp01 cp,.
    Cmf_Package_Components@arborp01 code of criminal procedure
    cmf_component_elements@arborp01 EAC,
    customer_contracts@arborp01 cc
    Where cp. Package_instance_id = cpc. Package_instance_id
    And cp. Package_instance_id_serv = cpc. Package_instance_id_serv
    And cpc.component_instance_id = cce.component_instance_id
    And cpc.component_instance_id_serv = cce.component_instance_id_serv
    And cce.association_id = cc.tracking_id
    And cpc.Component_id in (60584,90474,90475)
    And the EAC. Package_status = 1
    And the EAC. Inactive_dt is null
    And cce.association_type = 2

    Qry2 - join ANSI
    Select
    CP.account_no,
    CPC.id_value Subscr_no,
    cce.Component_id,
    CCE.active_dt,
    CP. Package_instance_id_serv
    Of Cmf_Packages@arborp01 cp
    Join Cmf_Package_Components@arborp01 cpc
    on (cp. Package_instance_id = cpc. Package_instance_id
    And cp. Package_instance_id_serv = cpc. Package_instance_id_serv)
    Join cmf_component_elements@arborp01 EAC
    on (cpc.component_instance_id = cce.component_instance_id
    And cpc.component_instance_id_serv = cce.component_instance_id_serv)
    Join Customer_contracts@arborp01 cc on cce.association_id = cc.tracking_id
    Where cpc.Component_id in (60584,90474,90475)
    And the EAC. Package_status = 1
    And the EAC. Inactive_dt is null
    And cce.association_type = 2


    An aplogize for my eanglish.
    Thank you

    Do you mean that the remote servers are running 8i?

    8i supported SQL 99 join syntax. So I would be quite surprised if forcing the instance of Oracle 9i local to do joins, representing the query Exchange plan.

    Justin

Maybe you are looking for