How do the query select outer join to a report of the APEX

Hi all

I'm Ann.

I have a select statement that is used to calculate statistics for a month (October 2012 in this example)
Select ph.phase_number
sum ((case
WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
THEN last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
Of OTHER ph.date_finished
END)
(-ph.date_started + 1) / count (def.def_id) as avg_days
Ph phase_membership
inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
join in-house defendant def on ce.defendant_id = def.def_id
where def.active = 1
and ph.date_started < = last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
and ph.active = 1
and UPPER (ce.court_name) LIKE '% '.
Rollup Group (phase_number)
;

The result is as below
Phase_Number AVG_DAYS
Phase One 8.6666666666666667
Phase two 14.6
Phase three 12
11.4615365

I have another list of selection mainly the list of months between two date value.
Select to_char (which_month, 'LUN YYYY') as display_month
de)
Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
of object
where
rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
order of which_month)

The query result is as below

DISPLAY_MONTH

AUGUST 2012
SEP 2012
OCT 2012

Is it possible I can join these two select statement above to generate a comparable result:

Days of month Phase number Avg
August 2012 Phase One 8.666
Sep 2012 Phase One 7.66
Oct 2012 Phase One 5,66
August 2012 Phase two 8.666
Sep 2012 Phase two 7.66
Oct 2012 Phase two 5,66
August 2012 Phase three 8.666
Sep 2012 Phase three 7.66
Oct 2012 Phase three 5,66

Or
Days of month Phase number Avg
August 2012 Phase One 8.666
August 2012 Phase two 7.66
August 2012 Phase three 5,66
Sep 2012 Phase One 8.666
Sep 2012 Phase two 7.66
Sep 2012 Phase three 5,66
Oct 2012 Phase One 8.666
Oct 2012 Phase two 7.66
Oct 2012 Phase three 5,66

And it can be controlled by Phase number or month.
My other colleague suggested I should use a left outer join, but after having tried many ways, I'm still stuck.

I tried select is
Select a.display_month, b.* in)
Select to_char (which_month, 'LUN YYYY') as display_month
de)
Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
of object
where
rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
order which_month)) a left outer join

(Select to_char (ph.date_finished, 'MY YYYY') as join_month, ph.phase_number)
sum ((case
WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (a.display_month, 'MY YYYY'))
THEN last_day (TO_DATE (a.display_month, 'MY YYYY'))
Of OTHER ph.date_finished
END)
(-ph.date_started + 1) / count (def.def_id) as avg_days
Ph phase_membership
inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
join in-house defendant def on ce.defendant_id = def.def_id
where def.active = 1
and ph.date_started < = last_day (TO_DATE (a.display_month, 'MY YYYY'))
and ph.active = 1
and UPPER (ce.court_name) LIKE '% '.
To_char (ph.date_finished, 'MY YYYY'), group (phase_number) rollup) b
On a.display_month = b.join_month

but then I get an error
SQL error: ORA-00904: "A." "" DISPLAY_MONTH ": invalid identifier

I need to view a report on the APEX with option for people to download at least format CSV.
Already 1 inteactive report in the page, so I don't think adds another interactive report without using the iframe trick.

If any of you have any ideas, please help.

Thank you very much.

Ann

Hello Ann,.

Frank has done a very good job. I am also impressed.

Is in regard to your correction to his question, the problem is on this replacement you did

last_day(TO_DATE(am.which_month,'MON YYYY'))

AM.which_month is already a date type, and you don't need to convert it to this day.
Here is the correct way:

last_day(am.which_month)

There are also sometimes with the data you've posted have no line for this month. So I also added a function NVL to display 0 under avg_days for these cases.

Here is my corrected query:

DEFINE startmonth = "Aug 2012";
DEFINE endmonth   = "Oct 2012";
WITH  all_months  AS
(
   SELECT ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM-1) AS which_month
   ,      ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM  ) AS next_month
   from all_objects
   where
   rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1))
)
SELECT TO_CHAR (am.which_month, 'Mon YYYY')  AS month
     , ph.phase_number
     , NVL(sum ( (CASE
                 WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(am.which_month)
                 THEN last_day(am.which_month)
                 ELSE ph.date_finished
              END
             ) - ph.date_started + 1
           ) / count(def.def_id), 0) as avg_days
  FROM all_months am
       LEFT OUTER JOIN  a_phase_membership  ph  PARTITION BY (ph.phase_number)
          ON  am.which_month <= ph.date_started
          AND am.next_month  >  ph.date_started
          AND ph.date_started <= last_day(am.which_month)  -- May not be needed
          AND ph.active = 1
       LEFT OUTER JOIN  a_engagement  ce
          ON  ph.mpm_eng_id = ce.engagement_id
          AND ce.court_name IS NOT NULL  -- or something involving LIKE
       LEFT OUTER join  a_defendant     def
          ON  ce.defendant_id = def.def_id
          AND def.active = 1
 GROUP BY ROLLUP(phase_number, am.which_month)
 ORDER BY  am.which_month
        ,  ph.phase_number
;

The output is:
MONTH    PHASE_NUMBER           AVG_DAYS
-------- -------------------- ----------
Aug 2012 PHASE ONE                     0
Aug 2012 PHASE THREE                   0
Aug 2012 PHASE TWO                     0
Sep 2012 PHASE ONE                    12
Sep 2012 PHASE THREE                   1
Sep 2012 PHASE TWO                     9
Oct 2012 PHASE ONE                     8
Oct 2012 PHASE THREE                   0
Oct 2012 PHASE TWO                    14
         PHASE ONE                    11
         PHASE THREE                   1
         PHASE TWO                  11.5
                              9.71428571

I don't know if that's really what you want. In the case check it and let me know.

Kind regards.
Al

Tags: Database

Similar Questions

  • 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 with outer join not dispalying the correct results

    Hi all

    I have a table that has a column called State it may be null or has the code that comes from the research b.When I use this query
    Select a b.menaing
    where a.status = b'lookup_code (+)
    AND b.lookup_type = 'MTH_BUSINESS_FUNCTION'
    AND b.LANGUAGE = USERENV ('LANG')

    so I don't understand the lines of table a, where the status is null

    and if I use the condition:
    Select a b.menaing
    where ((a.status IS NULL) OR)
    (a.status = b.lookup_code
    AND b.lookup_type = 'MTH_BUSINESS_FUNCTION'
    AND b.LANGUAGE = USERENV ('LANG')))

    Then, I get a lot of additional lines. You can soemone please tell me hwo to do (my query should display the menaing if the status column is empty, then it must show empty if not after to join the lookup table, it should show some sense)

    I don't get the rows in the table a, where the status is null

    You must outerjoin each predicate referencing table b.:

    select  b.menaing
      from  a,b
      where a.status=b.lookup_code(+)
        AND b.lookup_type(+)='MTH_BUSINESS_FUNCTION'
        AND b.LANGUAGE(+) = USERENV('LANG')
    /
    

    Or use:

    select  b.menaing
      from  a left join b
        on  a.status=b.lookup_code(+)
        and b.lookup_type='MTH_BUSINESS_FUNCTION'
        and b.LANGUAGE = USERENV('LANG')
    /
    

    SY.

  • How does the APEX 5 'Refresh' Action? Unable to refresh the page items.

    Hello

    I'm 5 APEX developed a page with both regions. Goal is to show the number of cells on the main area and allow to update the same number of cells from another region on the same page.

    Region 1: Added a view-only point P2_CELL_NUMBER_SHOW seen source of sql return the unique value. Like "Select cell_number of user_cell."

    Region 2 (hide this region during the loading of the page): adding an item of text P2_CELL_NUMBER_UPDATED. This region has added a button "Apply Changes". During the click on added dynamic actions in the following order:

    (a) PLSQL: Null; Submit article: P2_CELL_NUMBER_UPDATED

    (b) PLSQL: the UPDATE call sql statement to update the number of cells in the database table.

    (c) masking region 2 and region 1 via java script list.

    (d) refresh region 1 (here I expect at this point P2_CELL_NUMBER_SHOW should show the new update on the step value b). But get the old value that was earlier on region 1. But when submitting the page then region 1 get the new value.

    So, does send the page or set the session state to get the new value on region 1? Will update no help in this situation?

    Thank you

    Ankit

    Hi Pierre,.

    The dynamic Action of the type "Refresh", does not work on the elements and entry areas with elements of entry. It is intended for regions of report with PPR (partial Page Refresh) allowed namely interactive reports, classic and graphic regions.

    Kind regards

    Kiran

  • How we prevent date pushed out of page in reports 6i

    I have a simple bibliography of a request for reports 6i part. The bibliography consists of items scientists, reports, etc., and as with all articles, we can have anywhere from 1 to 10 or several authors collaborating on a publication.

    The layout is as follows (in an extensible framework) (points represent the spaces):

    AUTHOR... DATE_OF_PUBLICATION
    QUOTE

    Author and reference field properties allow expansion vertically and horizonally. Everything works well as long as the author list is shorter than the width of the page.

    But where we have a list very long author, two or more lines long, that the DATE_OF_PUBLICATION is pushed to another page where it is printed on its own. The next bibliography entry starts on page after page (third).

    Is it possible to keep DATE_OF_PUBLICATION from being pushed back on a separate page. I tried to use an anchor to follow the DATE_OF_PUBLICATION of the AUTHOR, but it doesn't seem to do anything.

    I need to have the DATE_OF_PUBLICATION AUTHOR of the suite and before QUOTE, even if it's several lines lower (as below)

    Author1, Author2, Name1, name2 blah blah blah on the edge of the page blah blah
    Enforcement12, name12... 2007

    Any suggestions please?

    Thanks in advance

    Glenn

    you could place a frame with horizontal elasticity back around the author field. make this field complete 90% of the width of the page and place the column date next to her.
    If you have a number of authors the field should shrink and take the fied date with her.
    If you have a very large number of authors that the list would take 90% of the pagewidth, spread over several lines, the dat field would place to the right end of the page at the top.

    I hope this helps.

  • He had to know the right outer join using...

    He had to know the right outer join using...

    For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)

    Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)

    In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...

    Hello

    chan001 wrote:

    He had to know the right outer join using...

    For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)

    Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)

    In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...

    The two examples above use the old syntax outer join of Oracle. (I guess there should be a sign inside the parentheses, e.g.. +)

    ...  WHERE E.DEPTNO = D.DEPTNO (+)

    )

    The LEFT OUTER JOIN and RIGHT OUTER JOIN terms apply only to the ANSI join syntax, e. g.

    .

    .. FROM EMP E

    DEPT LEFT OUTER JOIN D ON E.DEPTNO = D.DEPTNO

    As Blushadow said above, there's no real point in having LEFT OUTER JOIN and RIGHT OUTER JOIN;  What you can do with one (or a combination of both) can be done with the other.  Most people use LEFT OUTER JOIN systematically and never use RIGHT OUTER JOIN.

    There are situations where using a combination of the two would mean a little less striking, but only a little less and this kind of situation is very common, and one may wonder if the somewhat shorter code is more specific.  I suggest that forget you RIGHT OUTER JOIN.

  • Outer joins to the left... Please help!

    Hmm. Ive had trouble with this one for a while and have read and re-read docs etc.

    IM under 11.2 XE and its Apex 4.2 application...

    Its a simple query with outer joins... but I can't simply to do it right after several hours of trying! ID be very grateful if anyone can lend a hand...

    For the query below. I am looking for the following:

    Complete list of entities, a sum of the values if they exist (and obviously empty if they don't), filtered by a table of SUM choice only the records that match a value in the lookup table.

    Select

    e.ENTITY as ENTITY,

    Sum (p.amount) as Forecast_Income,

    Sum (BR.bri_credit) as Actual_Income,

    Sum (BR.bri_debit) as Actual_Expenses

    Of

    e entities

    LEFT OUTER JOIN payments p

    WE (e.entity_id = p.entity_id)

    LEFT OUTER JOIN pmt_stat_lookup ps

    WE (p.status_id = ps.status_id

    and ps.forecast = 'Y')

    LEFT OUTER JOIN bri_recon br

    WE (e.entity_id = br.entity_id)

    E.entity group

    My problem with the join where I join p.status_id for ps.status_id and ps.forecast = 'Y '...   If I run the above statement, it seems does not account for this filter criteria and summarizes all records of PAYMENTS, regardless of...  If I move outside the outer join clause, it only brings back the records of PAYMENTS where there is a join. Ive tried to join in a different order etc... but in vain...

    If someone could help, Id be very grateful.

    Kind regards

    Richard

    Hello Richard

    Try this query:

    SELECT e.entity as ENTITY

    sum (PO.amount) as Forecast_Income

    sum (br.bri_credit) as Actual_Income

    sum (br.bri_debit) as Actual_Expenses

    Of

    E ENTITIES

    LEFT OUTER

    JOIN (SELECT P.entity_id )

    P.amount

    PAYMENTS P

    JOIN PMT_STAT_LOOKUP PS

    ON p.status_id = ps.status_id

    AND ps.forecast = 'Y '.

    ) IN.

    WE e.entity_id = in. entity_id

    LEFT OUTER

    JOIN BR BRI_RECON

    ON e.entity_id = br.entity_id

    E.entity GROUP

    ;

    I hope it helps.

    Best regards, David

    Post edited by: David Berger

  • Outer join is not retrieve the correct values

    Hi, I have a problem to recover some data from this query with outer join:

    SELECT count (incident_id), range_2 of
    (by selecting range_2 in apps.aaa_table),
    (Select inc.incident_id,
    XXN2B_RESOLUTION_RANGE (2, ROUND (((TO_DATE (inc. INCIDENT_ATTRIBUTE_7, «hh24:mi:ss jj/mm/yyyy»)-inc. INC_RESPONDED_BY_DATE) * 24), 2)) VARIES
    Inc. stuff
    Inc. INVENTORY_ITEM_ID,
    prom_dt. Iptv_Sumptom - S? µpt? µA
    OF cs_incidents_all_b inc.,.
    cs_incidents_all_tl tl,
    cs_sr_type_mapping m,
    fnd_responsibility RESP,
    ntt xxntt.xxntt_incidents_support,
    xxntt.xxntt_incidents ntt_inc,
    XXe.xxe_tt_promitheas_dt prom_dt,
    20th. Xxe_Cs_Int_Sla als
    WHERE inc.incident_id = tl.incident_id
    AND tl. LANGUAGE = 'EL '.
    AND inc.incident_type_id = m.incident_type_id
    AND resp.responsibility_key IN (select SV. S fnd_flex_value_sets FLEX_VALUE, FND_FLEX_VALUES SV
    where s.FLEX_VALUE_SET_NAME = 'XXNTT_RESPONSIBILITIES. '
    AND S.FLEX_VALUE_SET_ID = SV. FLEX_VALUE_SET_ID)
    AND m.responsibility_id = resp.responsibility_id
    AND resp.end_date is null
    AND inc.incident_number = ntt.incident_number (+)
    AND inc.incident_number = ntt_inc.incident_number (+)
    AND inc.incident_id = prom_dt.incident_id (+)
    AND inc.incident_number = sla. Incident_Number (+)
    - and don't like '%0:00% ' TOTAL_INACT_SLA_DURATION
    (Inc. INC_RESPONDED_BY_DATE is not null AND INCIDENT_ATTRIBUTE_7 is not null)
    ) b.
    (select * from xxntt_custom_hierarchy)
    Union
    Select eidos null null omada, null product_categiory, stuff, null, null, inv_item_descripiption, null, tautopoihsh, inv_item_id double null null symptom
    ) c
    where a.range_2 = b.ranges (+)
    and c.INV_ITEM_ID (+) = b.INVENTORY_ITEM_ID
    and c.CATEGORY_ID (+) = b.CATEGORY_ID
    and c.SYMPTOM (+) = b.IPTV_SUMPTOM
    and c.OMADA = 'A '.
    Range_2 group

    This request is composed by 3 dataset: a, b and c

    the data group is a fixed list of values (LOV): range_2 = "0-2h','2-4h','4-6h','6-8h','8-10h','10-12h','12-14h','14-16h','16-18h','18-20h".

    the dataset b retrieve a list of the incident_id and their related ranges (calculated with the XXN2B_RESOLUTION_RANGE function)

    the c dataset is just a filter on the b of dataset to retrieve only the incident_id who belong to the group "A".

    I want to reach is this: always see the full list of values 'range_2', even if I do not have incident_id with a particular range.
    That's why I put the condition: a.range_2 = b.ranges (+)

    .. .but it does not work... I don't see the incident_id which have the scope inside the LOV... instead I want to see also if there is incident_id without a range to the LOV.

    Range_2 grouping, I see:

    ! http://www.freeimagehosting.NET/uploads/d900035c11.jpg!


    Instead of

    ! http://www.freeimagehosting.NET/uploads/99a75dfca4.jpg!

    Can someone help me understand where is the error?

    Thanks in advance

    Alex

    Hi Alex,

    I think you need to externally join the final predicate, thus:

    ..
    and c.OMADA(+) = 'A'
    ..
    

    Concerning
    Peter

  • Help with sql FULL OUTER JOIN

    Hi all
    I need assistance with SQL FULL OUTER JOIN.

    How to write with FULL OUTER JOIN, the query.
    I tried like


    I have 3 different queries.

    Query q: SELECT emp_id LN.emp_id.
    Sum (LN_amount) loan_amt
    MY_LON_TAB LN
    WHERE LN_amount > 20000
    LN.emp_id GROUP;



    Query b: SELECT PLN. EMP_ID emp_id,
    Sum (PLAN_AMOUNT) plan_amt
    FROM PLN MY_PLAN_TAB
    where PLAN_AMOUNT <>0
    GROUP BY PLN. EMP_ID;


    Query C:

    SELECT FLX. EMP_ID emp_id,
    SUM (PRORATE_AMOUNT) PRORATE_AMT
    OF MY_FLX_TAB FLX
    WHERE PRORATE_AMOUNT <>0
    FLX GROUP. EMP_ID;


    Suppose that the different subquery above 3 a, b, c respectively. each subquery with emp_id and respective amount.

    like a.emp_id, a.loan_amt
    b.emp_id, b.plan_amt
    c.emp_id, c.prorate_amt

    I show all the empid with their amount respective.
    schenario: If an account made, but not vice-versa b
    and B have record, but not vice versa c
    and a credit record but not vice versa c

    first: I have external is associated with the A and B
    Second: join external then complete the total outcome of (a & b) with c
    but empid c just as empty.


    My output is:

    emp_id a.loan_amt, b.plan_amt c.prorate_amt
    101 5000 null null
    102 4500 null 2000
    103 6700 null null


    How to solve the foregoing to the ANSI (FULL OUTER JOIN) method.
    Please suggest me.

    Thanks in advance...
    PKM

    Hello

    It is very difficult for anyone to say what you're doing wrong if they do not know what you are doing. Post your code FULL OUTER JOIN.
    My best guess is:

    WITH     a     AS
    (
         SELECT     ...      -- What you posted as query a
    )
    ,     b     AS
    (
         SELECT     ...      -- What you posted as query b
    )
    ,     c     AS
    (
         SELECT     ...      -- What you posted as query c
    )
    SELECT     COALESCE ( a.emp_id
               , b.emp_id
               , c.emp_id
               )     AS emp_id
    ,     ...     -- whatever other columns you want
    FROM          a
    FULL OUTER JOIN     b  ON     b.emp_id =            a.emp_id
    FULL OUTER JOIN     c  ON     c.emp_id = COALESCE (a.emp_id, b.emp_id)
    ;
    

    I hope that answers your question.
    If not, post a small example (CREATE TABLE and INSERT statements) data for all tables and the results expected from these data (if not what you have already posted).

  • [8i] need help with full outer join combined with a cross join...

    I can't understand how to combine a full outer join with a different type of join... is it possible?

    Here are some create table and insert for examples of database:
    CREATE TABLE     my_tab1
    (     record_id     NUMBER     NOT NULL     
    ,     workstation     VARCHAR2(4)
    ,     my_value     NUMBER
         CONSTRAINT my_tab1_pk PRIMARY KEY (record_id)
    );
    
    INSERT INTO     my_tab1
    VALUES(1,'ABCD',10);
    INSERT INTO     my_tab1
    VALUES(2,'ABCD',15);
    INSERT INTO     my_tab1
    VALUES(3,'ABCD',5);
    INSERT INTO     my_tab1
    VALUES(4,'A123',5);
    INSERT INTO     my_tab1
    VALUES(5,'A123',10);
    INSERT INTO     my_tab1
    VALUES(6,'A123',20);
    INSERT INTO     my_tab1
    VALUES(7,'????',5);
    
    
    CREATE TABLE     my_tab2
    (     workstation     VARCHAR2(4)
    ,     wkstn_name     VARCHAR2(20)
         CONSTRAINT my_tab2_pk PRIMARY KEY (workstation)
    );
    
    INSERT INTO     my_tab2
    VALUES('ABCD','WKSTN 1');
    INSERT INTO     my_tab2
    VALUES('A123','WKSTN 2');
    INSERT INTO     my_tab2
    VALUES('B456','WKSTN 3');
    
    CREATE TABLE     my_tab3
    (     my_nbr1     NUMBER
    ,     my_nbr2     NUMBER
    );
    
    INSERT INTO     my_tab3
    VALUES(1,2);
    INSERT INTO     my_tab3
    VALUES(2,3);
    INSERT INTO     my_tab3
    VALUES(3,4);
    And, the results that I want to get:
    workstation     sum(my_value)     wkstn_name     my_nbr1     my_nbr2
    ---------------------------------------------------------------
    ABCD          30          WKSTN 1          1     2
    ABCD          30          WKSTN 1          2     3
    ABCD          30          WKSTN 1          3     4
    A123          35          WKSTN 2          1     2
    A123          35          WKSTN 2          2     3
    A123          35          WKSTN 2          3     4
    B456          0          WKSTN 3          1     2
    B456          0          WKSTN 3          2     3
    B456          0          WKSTN 3          3     4
    ????          5          NULL          1     2
    ????          5          NULL          2     3
    ????          5          NULL          3     4
    I tried a number of different things, google my problem and no luck yet...
    SELECT     t1.workstation
    ,     SUM(t1.my_value)
    ,     t2.wkstn_name
    ,     t3.my_nbr1
    ,     t3.my_nbr2
    FROM     my_tab1 t1
    ,     my_tab2 t2
    ,     my_tab3 t3
    ...
    So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3. I wonder if I can't find examples of it online because it is not possible...

    Note: I'm stuck dealing with Oracle 8i

    Thank you!!

    Hello

    The query I posted yesterday is a little more complex that it should be.
    My_tab2.workstation is unique, there is no reason to make a separate subquery as mt1. We can join my_tab1 to my_tab2 and get the SUM in a subquery.

    SELECT       foj.workstation
    ,       foj.sum_my_value
    ,       foj.wkstn_name
    ,       mt3.my_nbr1
    ,       mt3.my_nbr2
    FROM       (     -- Begin in-line view foj for full outer join
              SELECT        mt1.workstation
              ,        SUM (mt1.my_value)     AS sum_my_value
              ,        mt2.wkstn_name
              FROM        my_tab1   mt1
              ,        my_tab2   mt2
              WHERE        mt1.workstation     = mt2.workstation (+)
              GROUP BY   mt1.workstation
              ,        mt2.wkstn_name
                            --
                    UNION ALL
                            --
              SELECT      workstation
              ,      0      AS sum_my_value
              ,      wkstn_name
              FROM      my_tab2
              WHERE      workstation     NOT IN (     -- Begin NOT IN sub-query
                                               SELECT      workstation
                                       FROM      my_tab1
                                       WHERE      workstation     IS NOT NULL
                                     )     -- End NOT IN sub-query
           ) foj     -- End in-line view foj for full outer join
    ,       my_tab3  mt3
    ORDER BY  foj.wkstn_name
    ,       foj.workstation
    ,       mt3.my_nbr1
    ,       mt3.my_nbr2
    ;
    

    Thanks for posting the CREATE TABLE and INSERT statements, and very clear expected results!

    user11033437 wrote:
    ... So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3.

    She, exactly!
    The trickiest part is when and how get SUM (my_value). You could address the question of exactly what my_tab3 must be attached to a cross that's exactly what should look like the result set of the full outer join between my_tab1 and my_tab2 to. To do this, take your desired results, remove columns that do not come from the outer join complete and delete duplicate rows. You will get:

    workstation     sum(my_value)     wkstn_name
    -----------     -------------   ----------
    ABCD          30          WKSTN 1
    A123          35          WKSTN 2
    B456          0          WKSTN 3
    ????          5          NULL          
    

    So the heart of the problem is how to get these results of my_tab1 and my_tab2, which is done in the subquery FOJ above.

    I tried to use auto-documenté in my code names. I hope you can understand.
    I could spend hours explaining the different parts of this query more in detail, but I don't know that I would lose some of that time, explain things that you already understand. If you want an explanation of the specific element (s), let me know.

  • 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

  • outer join on the aggregate query

    This is probably a relatively simple matter, as long as I explain it well enough:

    I have two tables:

    categorycodes and properties

    categorycodes is a lookup table.

    both tables have a catcode field which is a char (1) that contains matching data (only the numbers 1 to 6)

    CREATE

    TABLE CATEGORYCODES

    (

    CATCODE CHAR (1 BYTE) NOT NULL,

    DESCRIPTION VARCHAR2 (25 BYTE) NOT NULL,

    CONSTRAINT CATEGORYCODES_PK PRIMARY KEY (CATCODE) ALLOW

    )

    catCode

    1

    2

    3

    4

    5

    6

    The properties table has approximately 600 000 records. The properties table also has a field named parcelno which is a tank (9).  It contains a string of figures and numbers only.

    What I would like is:

    catCode, count (*)

    1 580

    2 300

    3 3000

    4 235

    5 0

    6 80

    I limited the results of the query to make sure it was a game that would not all catcodes in it.  I have trouble to get the one with zero to display.  I know that this has to do with how I do the join, but I don't know what.

    It is a sample of what I've tried:

    Select i.

    Of

    (select catcode, count (*)

    property p

    where substr (parcelno, 1, 3) = ' 871 "

    Catcode group) i

    outer join right categorycodes cc

    We i.catcode = cc.catcode;

    I'm not worried about the situations where catcode is null in the properties.  Parcelno cannot be null.

    Hello

    Looks like your query should work; except that you won't COUNT (*); That would make each issue at least 1.  COUNT (*) means that count the total number of lines, no matter what is on them, so he'll see the line with just the catcode of the lookup table that matches nothing and which count as 1.  You want to count the number of rows in the table of properties, so expect a column of the properties that cannot be NULL.

    Here is a slightly different way

    SELECT c.catcode

    EARL of (p.catcode) AS cnt

    OF categorycodes c

    P ON p.catcode = c.catcode LEFT OUTER JOIN properties

    AND SUBSTR (p.parcelno

    1

    3

    ) = ' 871 "

    ;

    If the condition about 871' ' part of the join condition, then you don't need a subquery.

    .

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Point where the above statement is erroneous results, and explain, using specific examples, how you get the right result of data provided in these places.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Outer join - problem with the name of the table in the select list

    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

    create table (j1)

    number of C1,

    number of C2);

    create table (j2)

    number of C1,

    number of C2);

    insert into values j1 (1, 10);

    insert into j1 values (1, 100);

    insert into values j1 (1, 1000);

    insert into values j2 (1, 2);

    insert into values j2 (1, 4);

    insert into values j2 (1, 8);

    commit;

    Select c1, j1.c2, j2.c2 of outer join of j1 j2 using (c1); - DOES NOT

    Select c1, j1 j2 (c1) using outer join j2.c2. - WORK

    Why?

    Hello

    Interesting question!  Oracle goes very far in trying not to trigger an error.

    The OUTER keyword (if used; it is always optional) must be preceded by one of the keywords, right or LEFT.  Since neither LEFT, RIGHT, or FULL comes before OUTER in queries in your first message, it does not recognize as keyword OUTER and treats him like a table alias for table j1.  Since j1 has an alias, the real table name cannot be used in the SELECT clause.  This query is executed:

    SELECT c1

    outer.c2

    j2.c2

    External J1

    Join the HELP of j2 (c1)

    ;

    There is an INTERNAL join.  Add to your sample data:

    insert into values of j1 (-1, -10);

    insert into values of j2 (-2, -20);

    to be specified.

    Moreover, USING is short for confUSING.  I suggest you use IT for all the join conditions.  Everyone (unless they you write or read a manual) does.

  • outer join on query with the GOLD clause

    Hi all, I have a problem outerjoining a clause or a request with
    Here's my data
    WITH table1 AS
    (
     SELECT  'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
     SELECT  null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
     SELECT  null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL
     SELECT  null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
     SELECT  'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
     SELECT  null txt1, NULL txt2, null txt3, null txt4 FROM dual 
    
    
    )
    ,table2 AS
    (
     SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
     SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
     SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL
      SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual 
    
    )
    SELECT b.pid, a.*
    from table1 a, table2 b
    WHERE (a.txt1 = b.txt1 OR
           a.txt1 IS NULL AND a.txt2=b.txt2 OR
           Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR
           Nvl(a.txt2, a.txt1) IS NULL  AND a.txt3 IS NULL AND a.txt4 = b.txt4
           ) 
    as you can see I am attaching the table 1 and table 2. I join with txt1, if txt1 is null, then join by txt2, if null, then reach by txt3 and so on.
    the above produces this output code
    PID     TXT1     TXT2     TXT3     TXT4
    ===     ====     ===   ==== ====
    111     test     pak      ced     su
    222             pak      ced2     su2
    333                     ced3     su3
    444                          su3
    This output is partially correct. only 4 lines were in display and two has been left out
     SELECT  'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
     SELECT  null txt1, NULL txt2, null txt3, null txt4 FROM dual 
    I tried to use the outer join, but oracle will complain that I can't use outerjoin with the GOLD clause.

    can someone modify my query to display the output below?
    PID     TXT1     TXT2     TXT3     TXT4
    ===    ====      ===   ====  ====
    111     test     pak      ced     su
    222             pak      ced2     su2
    333                     ced3     su3
    444                          su3
    NULL  NULL   NULL    NULL   NULL
         test5 

    Not sure you can do it with the style of the Oracle of outer joins, but open ANSI style joins is simple, in fact exactly as you had it.

    SQL> set null null;
    SQL> WITH table1 AS (
      2   SELECT  'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
      3   SELECT  null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
      4   SELECT  null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL
      5   SELECT  null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
      6   SELECT  'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
      7   SELECT  null txt1, NULL txt2, null txt3, null txt4 FROM dual),
      8  table2 AS (
      9   SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
     10   SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
     11   SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL
     12   SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual)
     13  SELECT b.pid, a.*
     14  from table1 a
     15     LEFT JOIN table2 b
     16        ON (a.txt1 = b.txt1 OR
     17            a.txt1 IS NULL AND a.txt2=b.txt2 OR
     18            Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR
     19            Nvl(a.txt2, a.txt1) IS NULL  AND a.txt3 IS NULL AND a.txt4 = b.txt4);
    
           PID TXT1   TXT2   TXT3   TXT4
    ---------- ------ ------ ------ ------
           111 test   pak    ced    su
           222 null   pak    ced2   su2
           333 null   null   ced3   su3
           444 null   null   null   su3
    null       text5  null   null   su3
    null       null   null   null   null
    

    John

  • OUTER JOIN query returns the results of JOIN IN-HOUSE 11.2.0.1.0

    I'm data transfer in 11.2.01.0 (Windows XP 32-bit) and I wanted to compare the sizes of table with the same Table name in two different patterns, ML and SILENT, with a FULL OUTER JOIN (to account for all the tables and NULL values in a diagram).

    The scheme of ML has 176 tables: schema TUT a 133 tables. The use of a standard INNER JOIN gives 131 paintings.

    I get precisely the results with a FULL OUTER JOIN I get with an INTERNAL JOIN (not the same NULL values so I know they exist).

    This happens in SQL-Plus, SQL_Developer and using Oracle Wire pilot of Data_Direct.

    Here is the code:

    Login: SYS as SYSDBA or SYSTEM (same results for either)

    SELECT M.TABLE_NAME, M.NUM_ROWS, T.TABLE_NAME, T.NUM_ROWS
    OF SYS. ALL_TABLES M FULL OUTER JOIN SYS. ALL_TABLES T ON M.TABLE_NAME = T.TABLE_NAME
    WHERE
    M.OWNER = 'ML' AND
    T.OWNER = 'TUT';

    Produce the same results with LEFT OUTER joins and RIGHT OUTER joins in ASI and Oracle (+) syntax.

    Any thoughts?

    Hello

    If you read what I posted, forget it. MScallion (below) gave the correct answerr.

    If conditions such as

    owner   = 'ML'
    

    in the WHERE clause, and then they will reject the rows of the result set formed by the join condition.

    The inner join returns only 131 lines where the two 'paintings' have the same table_names.
    The outer joins return multiple lines (133, 176 or 178) before the place WHERE the provision is applied , but the WHERE clause eliminates all lines except the 131 found by the inner join.

    Published by: Frank Kulash, July 10, 2010 14:23

Maybe you are looking for