Join with full pivot

Oracle 11.2.0.1

Windows

create table empdetails

(

number of EmpID,

EmpName varchar2 (30)

)

/

create the table saldetails

(

number of EmpID,

VARCHAR2 (10) months.

number of salamt

)

/

insert into empdetails values (1, 'John');

insert into empdetails values (2, 'Smith');

insert into empdetails values (4, 'Robert');

insert into empdetails values (3, 'Joseph');

insert into empdetails values (7, 'Téo');

insert into saldetails values (2, 'July', 200);

insert into saldetails values (6, 'May', 150);

insert into saldetails values (1, 'May', 150);

insert into saldetails values (1, 'June', 150);

insert into saldetails values (1, 'July', 175);

insert into saldetails values (4, 'June', 180);

SQL > select * from empdetails;

EMPID EMPNAME

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

1 John

2 Smith

4 Robert

3 Joseph

Khaoula 7

SQL > select * from saldetails;

EMPID MONTHS SALAMT

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

2 July 200

May 6 150

May 1 150

June 1 150

1 July 175

June 4 180

6 selected lines.

SQL >

Power required:

EMPID EMPNAME April May June July

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

1 Jean 150 150 175

2 Smith                                                    200

3 Joseph

4 Robert 180

6                                 150

Khaoula 7

Logic for column of April, may, June and July.  Saldetails table have the processing of data from may, June and July, in the desired output, we need to have min (months) - 1 to max (month).

Thank you.

HI - find the minimum of months given month is not a big deal, but as said above to rotate based on months, than we need to know the name of the months before hand. If we know not what month we would not be able to provide the name of this month under the name of the column in the SELECT query.

However, there is a solution: in this approach, you build him SELECT queries dynamically, and then run it.

Reference: https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:4471013000346257238

http://technology.AMIS.nl/2006/05/24/dynamic-SQL-pivoting-stealing-Antons-Thunder/

For example:

Connected to:

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

With partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

-create a temporary table after joining the 2 data tables (instead you can try giving this query in the procedure below directly)

SQL > create table tmp_1 like

2 with t as (select e.empname, nvl (e.empid, s.empid) empid, s.month, s.salamt, to_char (min (to_date(s.month,'MON')) over () - 1, 'Month') min_month

3 of e empdetails

4 full outer join

5 s saldetails

6 on (e.empid = s.empid)

7             )

8 select

9 of

10 (select empname, empid, salamt, month

11 t

12 union

13. Select null, null, null, min_month

14 t

15 where rownum = 1

16)

17.

Table created.

-create procedure that generates the SELECT dynamically query and run it

SQL > create or replace procedure dynamic_pvt (p_cursor in the sys_refcursor)

2 is

3 clob l_query: = 'select empid, empname;

4 start

5

6 x (select distinct month of tmp_1 where the month is not null order by to_date (month, 'Month'))

7 loop

8 l_query: = l_query |

9. replace (q'|, sum (decode(month,'$X$',salamt)) $X$ |',)

10                      '$X$',

11 x.month / * sys.dbms_assert.simple_sql_name (x.empid) * /.

12                    );

13 end of loop;

14

15 l_query: = l_query | 'from tmp_1 group by empid, empname order by empid;

16 open p_cursor for l_query;

17

18 end;

19.

Created procedure.

SQL > variable refcursor x

SQL > execute dynamic_pvt(:x)

PL/SQL procedure successfully completed.

SQL > print x

EMPID EMPNAME APRIL MAY JUNE

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

JULY

----------

1 John                                             150        150

175

2 Smith

200

3 Joseph

EMPID EMPNAME APRIL MAY JUNE

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

JULY

----------

4 Robert                                                      180

6                                                  150

Khaoula 7

EMPID EMPNAME APRIL MAY JUNE

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

JULY

----------

7 selected lines.

SQL > col 9999 empid format

SQL > col empname format a30

SQL > col April format 9999

SQL > col can format 9999

SQL > col June format 9999

SQL > format of July col 9999

SQL > execute dynamic_pvt(:x)

PL/SQL procedure successfully completed.

SQL > print x

EMPID EMPNAME APRIL MAY JUNE JULY

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

1 Jean 150 150 175

2 Smith                                              200

3 Joseph

4 Robert                                       180

6                                        150

Khaoula 7

7 selected lines.

SQL >

Tags: Database

Similar Questions

  • [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.

  • [PIVOT] amount to combine with other pivot?

    Hello.

    I have this statement in my 11g database:

    WITH my_data AS
           (    SELECT    'pave'
                       || MOD( LEVEL
                             , 2
                              )
                         AS pave_name
                     , MOD( LEVEL
                          , 2
                           )
                         AS pave_version_nr
                     ,    'Cogr'
                       || FLOOR(   (  1
                                    + LEVEL )
                                 / 2
                                )
                         cogr_name
                     , LEVEL AS value_init
                     , 2 AS value_delivery
                     , 'fakjfhajhfkajöfdsgaösfdghöaoifdsgöafsghöa' AS coin_names
                  FROM DUAL
            CONNECT BY LEVEL < 9)
      SELECT *
        FROM (SELECT ROW_NUMBER( )
                       OVER( PARTITION BY cogr_name
                             ORDER BY
                               pave_name
                             , pave_version_nr
                            )
                       AS set_id
                   , cg.*
                FROM my_data cg                                                                                                               --
                               )
    ORDER BY cogr_name;
    

    where this result:

    PAVE_NAME PAVE_VERSION_NR COGR_NAME VALUE_DELIVERY COIN_NAMES VALUE_INIT SET_ID

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

    1 pave0 0 Cogr1 2 2 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    2 pave1 1 Cogr1 1 2 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    1 pave0 0 Cogr2 4 2 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    2 pave1 1 Cogr2 2 3 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    1 pave0 0 6 Cogr3 2 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    2 pave1 1 Cogr3 2 5 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    1 pave0 0 Cogr4 2 8 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    2 pave1 1 Cogr4 2 7 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    For each separate COGR_NAME, I need to compare, VALUE_INIT, VALUE_DELIVERY and COIN_NAMES.

    so my desired output is:

    PAVE_NAME_1 PAVE_VERSION_NR_1 COGR_NAME_1 VALUE_INIT_1 VALUE_DELIVERY_1 COIN_NAMES_1 PAVE_NAME_2 PAVE_VERSION_NR_2 COGR_NAME_2 VALUE_INIT_2 VALUE_DELIVERY_2 COIN_NAMES_2

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

    pave0 0 Cogr1 2 2 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa pave1 1 Cogr1 1 2 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    pave0 0 Cogr2 4 2 pave1 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa 1 Cogr2 2 3 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    pave0 0 Cogr3 2 6 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa pave1 1 Cogr3 2 5 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    pave0 0 Cogr4 8 2 pave1 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa 1 Cogr4 2 7 fakjfhajhfkajofdsgaosfdghoaoifdsgoafsghoa

    I tried a solution COGR_NAME and max() uses groups to keep (dense_rank last/first order of set_id) but it does not work with COIN_NAMES which is really a CLOB.

    So I guess it's possible with the pivoting of the query but any other solution is also welcome...

    Good bye

    DPT

    Hello

    One way is with a self-join, like this:

    WITH got_analytics AS

    (

    SELECT d. *- or whatever the desired columns

    ROW_NUMBER () OVER (PARTITION BY cogr_name

    ORDER BY pave_name

    pave_version_nr

    ) AS set_id

    , COUNT (*) OVER (PARTITION BY cogr_name

    ) AS n_rows

    OF my_data d

    )

    SELECT a1.*, a2. *- or other columns of your choice

    Got_analytics A1

    JOIN a2 ON a1.cogr_name = a2.cogr_name got_analytics

    WHERE a1.set_id = 1

    AND a2.set_id = a2.n_rows

    ORDER BY a1.cogr_name

    ;

  • 2135 HP all-in one: cannot print full Page A4, but can scan A4 with FULL Page

    Hi HP & friends,.

    Hello I am using 2135 HP all-in-one printer with windows 7 64 bit,

    I have some problems, and maybe I need your help to solve my problem.

    First of all, I'm trying to scan or copy the test page, I can't scan A4 paper with full size and then I'm trying to reset the configuration on the scan of the letter in A4 format and voila I can scan using A4 format with full screen.

    But my problem occurs when I try to use the file that I scan to be printed, I have a cut off area or empty the bottom of the page. Hmm I have a set configuration with A4 before printing the document.

    I am trying to attach images to show on my problem.

    Thanks for the attention and the solution

    Concerning

    Spoiler (Highlight to read)

    Hello

    Your printer model do not support a full borderless printing, must not exceed the specified margin and it is a limitation of the hardware.

    You can find his record of handling of paper below:

    Borderless printing: No
    http://www8.hp.com/in/en/products/printers/product-detail.html?oid=7174564#!tab=specs
    

    Minimum printer margins are 2.96 mm high, right and 14.5 mm (1.45 cm) for the lower left margins and margins of the page, the printer cannot exceed and to print on these margins, see the section called paper handling > margins below:

    http://support.HP.com/us-en/product/HP-DeskJet-ink-advantage-2130-all-in-one-printer-series/7174559/model/7174560/document/c04616318/

    Kind regards

    Shlomi

  • join with condition

    Hi all

    Is there a possible way to cross the join with condition?

    I want something like this:

    Table A: custid, accu_id, sum

    CustID, accu_id unique =

    CustomerID amount accu_id

    10 25 400

    10 35 447

    10 29 420

    20 30 510

    30 35 472

    .

    .

    .

    Table b: accu_id, description

    accu_id description

    shoes 25

    Book 29

    30 computer

    pen 35

    Note: in table A, it is a mismatch of the accu_id values that do not use. Please, take into account this.

    I want to see all the columns in the TABLE B for each custid in A. TABLE (something like cross join but with ONE article.) The following query does not work.

    Select * from a right join B on A.accu_id = B.accu_id;

    10-25

    10-29

    10-30

    10-35

    20-25

    20-29

    20-30

    20-35

    30 25

    30 29

    30 30

    30-35

    What should I do for this?

    Thanks in advance

    Use partition outer join:

    with a (too)

    Select double union all 10 custid, accu_id 25, amount 400

    Select 10,35,447 from all the double union

    Select 10,29,420 from all the double union

    Select 20,30,510 from all the double union

    Select double 30,35,472

    ),

    b like)

    Select accu_id 25, "shoe" description of all the double union

    Select 29, 'book' from dual union all

    Select 30, 'computer' from dual union all

    Select 35, 'pen' from dual

    )

    Select a.custid,

    a.accu_id,

    a.amount,

    b.

    a

    by (a.custid) partition

    right join

    b

    On a.accu_id = b.accu_id

    order of a.custid,

    a.accu_id

    /

    AMOUNT ACCU_ID CUSTID DESCRIPT
    ---------- ---------- ---------- --------
    10 25 400 shoe
    10 29 420 book
    10 35 447 pen
    10 computer
    20 30 510 computer
    shoe 20
    book 20
    20                       pen
    30 35 472 pen
    30 shoe
    30 book

    AMOUNT ACCU_ID CUSTID DESCRIPT
    ---------- ---------- ---------- --------
    30 computer

    12 selected lines.

    SQL >

    SY.

  • Trouble with the pivot and the columns that contain numbers/spaces

    Hello

    I have trouble with the pivot statement.
    How could I do this just for columns that are numbers?
    How could I do this just for columns that contain spaces?

    Can someone please help?


    based on the documentation of Carsten Czarski
    http://SQL-PLSQL-de.blogspot.com/2007/08/kreuztabellen-in-Oracle11g-SQL-pivot.html

    essentially to help:
    --------------------
    Select deptno, sum (clerk), sum (salesman), sum (manager)
    of (emp) pivot
    Sum (SAL) of EMPLOYMENT
    in ("CLERK" as a 'CLERK', 'SELLER' as 'SELLER', 'MANAGER' as 'MANAGER')
    )
    Deptno group
    --------------------
    DEPTNO SUM (CLERK) SUM (SALESMAN) SUM (MANAGER)
    ---------- ---------- ------------- ------------
    30 950 5600 2850
    20 1900 2975
    10-1300-2450



    I tried to run at my own table:

    NAME MONAT WERT
    -------------------------------------------------- ---------- ----------
    5 Antarctica 404,84
    Asia 7 106,41
    Oceana 2 456,96
    4 the Europe 426,23
    9 Antarctic 537,56
    Europe 9 832,58
    The South America 12 662,41
    Europe 4 422,27
    America of the North 7 312,19
    America of the North 10 148,92

    10 selected lines.


    But running:
    --------------------
    SELECT name, sum (1), sum (2), sum (3), sum (4), sum (5), sum (6), sum (7), sum (8), sum (9), sum (10), sum (11), sum (12)
    (pivot) apex_wksp.demo_pivot2
    Sum (Wert) for monat
    in ('1 ', '2', ' 3', '4 ', '5', '6', '7',' 8 ', ' 9',' 10', ' 11 ', ' 12')
    )
    Group by name
    ;
    --------------------
    led to:
    Antarctica 1 2 3 4 5 6 7 8 9 10 11 12
    North America 1 2 3 4 5 6 7 8 9 10 11 12
    Oceana 1 2 3 4 5 6 7 8 9 10 11 12
    The South America 1 2 3 4 5 6 7 8 9 10 11 12
    Europe 1 2 3 4 5 6 7 8 9 10 11 12
    Asia 1 2 3 4 5 6 7 8 9 10 11 12
    6 selected lines.


    not quite what I expected.





    In addition,
    --------------------
    Select monat, sum (Antarctica), sum (North America), sum (Oceana), sum (South America), sum (Europe), sum (Asia)
    (pivot) apex_wksp.demo_pivot2
    Sum (Wert) name
    ("Antarctic", "North America", "Oceana", "South America", "Europe", "Asia")
    )
    Group by name
    ;
    ---------------------
    ORA 907 results



    I know what the problem is - but how do I do it right?


    using double quotes or replace (ing) space with just underscores seems to garble sql for the unreadable.




    Help, please.



    Thanks in advance,
    Michael Weinberger

    Attention to the rotated default column alias:

    SQL> with demo_pivot2 as (
      2                       select 'Antarctica' name,5 monat,404.84 wert from dual union all
      3                       select 'Asia',7,106.41 from dual union all
      4                       select 'Oceana',2,456.96 from dual union all
      5                       select 'Europe',4,426.23 from dual union all
      6                       select 'Antarctica',9,537.56 from dual union all
      7                       select 'Europe',9,832.58 from dual union all
      8                       select 'South America',12,662.41 from dual union all
      9                       select 'Europe',4,422.27 from dual union all
     10                       select 'North America',7,312.19 from dual union all
     11                       select 'North America',10,148.92 from dual
     12                      )
     13  select name, sum("'1'"),sum("'2'"),sum("'3'"),sum("'4'"),sum("'5'"),sum("'6'"),sum("'7'"),sum("'8'"),sum("'9'"),sum("'10'"),sum("'11'"),sum("'12'")
     14  from demo_pivot2 PIVOT (
     15  sum(wert) for monat
     16  in ('1','2','3','4','5','6','7','8','9','10','11','12')
     17  )
     18  group by name
     19  ;
    
    NAME          SUM("'1'") SUM("'2'") SUM("'3'") SUM("'4'") SUM("'5'") SUM("'6'") SUM("'7'") SUM("'8'") SUM("'9'") SUM("'10'") SUM("'11'") SUM("'12'")
    ------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------- ----------- -----------
    Antarctica                                                    404.84                                      537.56
    North America                                                                       312.19                            148.92
    Oceana                       456.96
    South America                                                                                                                                 662.41
    Europe                                              848.5                                                 832.58
    Asia                                                                                106.41
    
    6 rows selected.
    
    SQL> 
    

    SY.

  • How to get previews of lower quality when working with Full-HD?

    I work with Full-HD video, but I don't have to preview the files (rendering) to be too the 1920 x 1080. It takes a lot of disk space and a lot of time to make the preview files.

    Is it possible to ensure a lower quality? For example, resolution 720 x 405 would be sufficient.

    But when I want to make a permanent export, I need to get the Full HD video.

    Thank you!

    Use a custom sequence and change previews as you wish.

  • Left Join with a subquery

    Hey everybody!

    I have some difficulty in trying to create a SQL query.

    I have the following tables:

    -Table Products: Product list
    CREATE TABLE (PRODUCTS)
    PRODUCT_ID INTEGER NOT NULL,
    KEY ("PRODUCT_ID") PRIMARY CONSTRAINT 'PK_PRODUCTS '.
    );

    -Orders table: Decreed this product
    CREATE TABLE ORDERS)
    ORDER_ID INTEGER NOT NULL,
    PRODUCT_ID INTEGER NOT NULL, / * FK PRODUCTS (PRODUCT_ID) * /.
    KEY ("ID_PEDIDO") PRIMARY CONSTRAINT 'PK_ORDERS '.
    );

    -Orders_Approval table: register when an order is approved
    CREATE TABLE ORDERS_APPROVAL)
    ORDER_ID INTEGER NOT NULL, / * FK ORDERS (ORDER_ID) * /.
    APPROVAL_DATE DATE NOT NULL,
    USER_ID INTEGER,
    KEY("ORDER_ID","APPROVAL_DATE") PRIMARY CONSTRAINT 'PK_ORDERS_APPROVAL '.
    );

    -Table Orders_ApprovalData: Register more details on the amenities of the order
    CREATE TABLE ORDERS_APPROVAL_DETAILS)
    APPROVALDET_ID INTEGER NOT NULL,
    ORDER_ID INTEGER NOT NULL, / * FK ORDERS_APPROVAL (ORDER_ID) * /.
    APPROVAL_DATE DATE NOT NULL, / * FK ORDERS_APPROVAL (APPROVAL_DATE) * /.
    KEY ("APPROVALDET_ID") PRIMARY CONSTRAINT 'PK_ORDERS_APPROVAL_DETAILS '.
    );

    The thing is that an order may OU cannot be approved. Thus, there could be no record of an order in ORDERS_APPROVAL.

    In addition, an order can have more than one approval.

    Here is the data that I use:

    /===========\
    | PRODUCTS |
    |===========|
    | PRODUCT_ID |
    |===========|
    | 1.
    |===========|
    | 2.
    |===========|
    | 3.
    \===========/

    /========================\
    | ORDERS |
    |========================|
    | ORDER_ID | PRODUCT_ID |
    |===========|============|
    | 27. 1.
    |===========|============|
    | 28. 2.
    |===========|============|
    | 29. 3.
    \===========|============/

    /=========================================\
    | ORDERS_APPROVAL |
    |=========================================|
    | ORDER_ID | APPROVAL_DATE | USER_ID.
    |===========|================|============|
    | 27. 01/10/2009 | 56.
    |===========|================|============|
    | 27. 04/10/2009 | 96.
    |===========|================|============|
    | 29. 03/10/2009 | 77.
    \===========|================|============/

    /=============================================\
    | ORDERS_APPROVAL_DETAILS |
    |=============================================|
    | APPROVALDET_ID | ORDER_ID | APPROVAL_DATE |
    |================|===========|================|
    | 1. 27. 01/10/2009 |
    |================|===========|================|
    | 2. 27. 04/10/2009 |
    |================|===========|================|
    | 3. 29. 03/10/2009 |
    \================|===========|================/
    I need to create a query that returns the data in all tables, but for orders with more than one certification,
    the query must return only the last record. It is also necessary return orders that have not yet been approved.

    My first query looked like this:

    SELECT
    *
    Of
    ORD IN ORDERS,
    PRODUCT PROD,
    ORDERS_APPROVAL ORDAPPROV,
    ORDERS_APPROVAL_DETAILS ORDAPPDET
    WHERE
    PROD. PRODUCT_ID = DSB. PRODUCT_ID
    AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
    AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
    AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE

    PS: I use the Oracle 8 syntax because it's the server I'll use. In addition, I can't change the design of database.

    This query returns the data in table all. Because I used LEFT JOIN "(+)" to join the table orders_approval with the orders table, I am able to see even the orders with no approval.

    But this way, I see also two approvals for order 27 (with the data above, this order was approved twice). I need to reach my paintings in the last approval for each order is but should be a left join so I can see the orders with no approval.

    I tried this way:

    SELECT
    *
    Of
    ORD IN ORDERS,
    PRODUCT PROD,
    ORDERS_APPROVAL ORDAPPROV,
    ORDERS_APPROVAL_DETAILS ORDAPPDET
    WHERE
    PROD. PRODUCT_ID = DSB. PRODUCT_ID
    AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
    --Also added the line below
    AND ORDAPPROV. APPROVAL_DATE = (SELECT MAX (APPROVAL_DATE) OF ORDERS_APPROVAL WHERE THE ORDER_ID = ORDAPPROV. ORDER_ID)
    AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
    AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE

    But in this way, as I am specifying I want only records with approval equal to date at the latest for each order, I do not see the order without approval.

    I tried again, with a left join like this:

    SELECT
    *
    Of
    ORD IN ORDERS,
    PRODUCT PROD,
    ORDERS_APPROVAL ORDAPPROV,
    ORDERS_APPROVAL_DETAILS ORDAPPDET
    WHERE
    PROD. PRODUCT_ID = DSB. PRODUCT_ID
    AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
    --Also added the line below
    AND ORDAPPROV. APPROVAL_DATE (+) = (SELECT MAX (APPROVAL_DATE) OF ORDERS_APPROVAL WHERE THE ORDER_ID = ORDAPPROV. ORDER_ID)
    AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
    AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE

    But I get a syntax error. Oracle said that it is not possible to do a join with a subquery.

    If anyone knows how I can bring all this data?

    Thanks in advance.

    Published by: user9936895 on 05/10/2009 09:42: tried to fix the predetermined data schema.

    Hello

    Welcome to the forum!

    A scalar, such as subquery

    (SELECT MAX(APPROVAL_DATE) FROM ORDERS_APPROVAL WHERE ORDER_ID=ORDAPPROV.ORDER_ID)
    

    is allowed in a WHERE clause, but not as a condition of outer join, as you discovered.

    A workaround is the query expression so that it is not part of the outer join condition, which invlove in May (as in this case), adding another subquery. In the following query, the table of orders_approval in your original OF Division is replaced with online view, which uses the exact same scalar subquery in the WHERE clause. The online display will only contain one line per order_id (assuming that there is no link with for last approval_date).

    SELECT
         *
    FROM
         orders               ord,
         products          prod,
         (     -- Begin in-line view ORDAPPROV of last approval_date only
         SELECT     *       -- or list the columns needed in main query
         FROM     orders_approval         oa
         WHERE     approval_date = (
                        SELECT  MAX (approval_date)
                        FROM     orders_approval
                        WHERE     order_id     = oa.order_id
                        )
         )                ordapprov,
         orders_approval_details ordappdet
    WHERE
         prod.product_id               = ord.product_id
    AND     ordapprov.order_id (+)          = ord.order_id
    AND     ordappdet.order_id (+)          = ordapprov.order_id
    AND     ordappdet.approval_date (+)     = ordapprov.approval_date
    ;
    

    Thank you for including CREATE TBAL statements; It is very useful.
    You want to be even more useful in the future? Post INSERT statements for the sample data. That will make it easier for people to respond and easier for them to test their ideas.

  • Left Outer Join with sum

    Dear elders,



    Firstly, sorry if my question is considered to be 'very novice' but I have this problem of confusion.

    Can I use the left outer join with summary?
    For example:

    Work table
    JobCode      JobGroupCode      
    111A         1100              
    112B         1100               
    113C         1100
    121A         1200
    333F         3300               
    Table No.
    JobGroupCode    ParentCode
    1100            1000
    1200            1000
    1300            1000
    3300            3000
    Activity table
    Jobcode      Mandays
    111A         5
    112B         7
    113C         3
    I want to choose with this result
    Job.JobCode    Job.JobGroupCode     JobGroup.Parentcode       Mandays
    111A           1100                 1000                      5
    112B           1100                 1000                      7               
    113C           1100                 1000                      3
    121A           1200                 1000                      0
    333F           3300                 3000                      0
    All I did was:
    select j.jobcode, j.jobgroupcode, jg.parentcode, sum(a.mandays)
      from job j
     inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode
      left join activity a on j.jobcode = a.jobcode
     group by j.jobcode, j.jobgroupcode, jg.parentcode
    and I got was only jobcode activity table, not exactly what I want to get all the work table jobcode. Could you please tell me, where I was wrong?

    result
    Job.JobCode    Job.JobGroupCode     JobGroup.Parentcode       Mandays
    111A           1100                 1000                      5
    112B           1100                 1000                      7               
    113C           1100                 1000                      3
    Thank you very much.

    Published by: user11197113 on May 25, 2009 03:31

    Published by: user11197113 on May 25, 2009 03:32

    Hello (and welcome!).

    Edit

    OK, try this:

    select j.jobcode, j.jobgroupcode, jg.parentcode, NVL(sum(a.mandays),0)
      from job j
     inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode
      left join activity a on j.jobcode = a.jobcode
     group by j.jobcode, j.jobgroupcode, jg.parentcode
    

    That will give you this:

    JOBC JOBG PARE SUM(A.MANDAYS)
    ---- ---- ---- --------------
    111A 1100 1000              5
    112B 1100 1000              7
    113C 1100 1000              3
    121A 1200 1000              0
    333F 3300 3000              0
    

    These are real results of your test data.

  • Outer join with a constant

    Outer join when made between the columns of the two tables is easy to understand and I'm familiar with it. But when it comes to the same join with a constant, my head starts spinning... you guys can help me with this? I would appreciate that show you with examples.
    Thanks a ton.

    Hello

    >
    Ok... I want to understand the output of the last sql statement given here.
    ...
    Select * from a, b
    where col_a (+) = col_b
    and col_a (+) = 1

    It shows put it is as follows
    col_a, col_b
    1 1
    2 NULL
    NULL NULL

    Joining means: 'display all rows in table b and the corresponding rows in the table one '.
    Since it is an outer join, it also means "view b lines even if there is no corresponding row in a.

    Thus, the output contains 3 lines, which correspond to the 3 lines in b.
    Only one of them (the one with col_b = 1) had a game in a.col_a, if the column is NULL in the other lines.

    With the sample data you posted, you will get the same results without condition

    and     col_a (+) = 1
    

    If you want to understand what makes this condition, use some examples of data where this condition would fail.
    For example, add this line to the table a:

    insert into a values (2);
    

    and run your original query (including the)

    and     col_a (+) = 1
    

    ). what output you get? You get the same exact results you did without the new line in a.

    In other words, the b line where col_b = 2 has still no matches in the table has.
    True, there is now a line of table where col_a = 2, but which does not constitute a game. A match is defined by two conditions:

    where   col_a (+) = col_b
    and     col_a (+) = 1
    

    in order to have a pair of lines which meets only the first condition

    where   col_a (+) = col_b
    

    is not enough.

  • HELP SQL (auto / full outer join with date corresponding)

    I'm having a hard time get this query nailed... hoping someone can help me sorted.

    create table tab1 (identification number,

    date of eff_date,

    Code1 varchar2 (2),

    Code2 varchar2 (2)

    )

    /

    insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (2, to_date('2015-03-19','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (2, to_date('2015-08-28','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (2, to_date('2015-11-12','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (2, to_date('2015-01-03','YYYY-MM-DD'), "DAT", "AE");

    insert into tab1 values (2, to_date('2015-03-14','YYYY-MM-DD'), "DAT", "AE");

    insert into tab1 values (2, to_date('2015-04-18','YYYY-MM-DD'), "DAT", "AE");

    insert into tab1 values (2, to_date('2015-09-14','YYYY-MM-DD'), "DAT", "AE");

    insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), "DAT", "BS");

    insert into tab1 values (2, to_date('2015-02-14','YYYY-MM-DD'), "DAT", "BS");

    insert into tab1 values (2, to_date('2015-03-14','YYYY-MM-DD'), "DAT", "BS");

    insert into tab1 values (2, to_date('2015-05-14','YYYY-MM-DD'), 'DAT', 'BE');

    insert into tab1 values (3, to_date('2015-09-16','YYYY-MM-DD'), 'DAT', 'AS');

    insert into tab1 values (3, to_date('2015-04-16','YYYY-MM-DD'), "DAT", "AE");

    tab1

    ID, date, code 1, code2

    2. DID DAT 2015-01-14

    2. DID DAT 2015-03-19

    2. DID DAT 2015-08-28

    2. DID DAT 2015-11-12

    2 AE DAT 2015-01-03

    2 AE DAT 2015-03-14

    2 AE DAT 2015-04-18

    2 AE DAT 2015-09-14

    2 BS DAT 2015-01-14

    2 BS DAT 2015-02-14

    2 BS DAT 2015-03-14

    BE DAT 2 2015-05-14

    3. DID DAT 2015-09-16

    3 AE DAT 2015-04-16

    What I need to do...

    1 auto join to match EI for each partition ID

    2. THAT the date must be less than or equal to the date of the AE and when there is more then a line corresponding to this criterion has chosen the date of closest EI of the date of the ACE.

    3. it must be a full outer join because I want to show all lines, even if it is not a match.  There is a beginning, but not record end end gold but no record of departure

    4. If there is an AE line for many AS lines (the SA date is less then equals the date of EI) then join this AE line to all 3 rows of ACE

    5. the same rules for BS and BE.

    result should look like this.

    ID, date, code 1, id_1 code2, date_1, code1_1, code2_1

    2 2015-01-14 DAT AS 2 AE DAT 2015-03-14

    2 2015-03-19 DAT AS 2 AE DAT 2015-04-18

    2 2015-08-28 DAT AS 2 AE DAT 2015-09-14

    2 2015-11-12 DAT DID ZERO ZERO ZERO ZERO

    NO NO NO NO 2 AE DAT 2015-01-03

    2015-01-2 14 DAT BS 2 BE DAT 2015-05-14

    2015-02-2 14 DAT BS 2 BE DAT 2015-05-14

    2015 03-2 14 DAT BS 2 BE DAT 2015-05-14

    3 2015-09-16 DAT DID ZERO ZERO ZERO ZERO

    NO NO NO NO 3 AE DAT 2015-04-16

    My attempt was somewhat along these lines (dealing only with SA / combos AE) but it does not manage the many scenarios one (req 4).

    Select a.*, b.* from

    (select row_number () on the rn (partition by a.id order a.eff_date), a.*)

    of tab1 where a.code2 = 'AS') a

    full outer join

    (select row_number () on the rn (b.eff_date order by b.id partition), b.*)

    tab1 b where b.code2 = 'Æ') b

    on a.id = b.id

    and a.rn = b.rn

    and a.eff_date < = b.eff_date

    Hello

    owbdev99 wrote:

    I'm having a hard time get this query nailed... hoping someone can help me sorted.

    create table tab1 (identification number,

    date of eff_date,

    Code1 varchar2 (2),

    Code2 varchar2 (2)

    )

    /

    insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), 'DAT', 'AS');

    ...

    Thanks for posting the CREATE TABLE and INSERT.  I know it can be a lot of trouble.  You want to get answers that work, not you?  Make sure that the statements you post too much work.  Test (and, if necessary, attach) your statements before committing.  You said code1 be VARCHAR2, but all the instructions insertion have values of 3 characters for code1.

    You are on the right track, with an analytical function, but ROW_NUMBER solves this problem.  1 "THAT line" could correspond to the 1st, 2nd, 3rd or any other line 'AE' and vice versa.  Try to use the analytical MIN function instead or ROW_NUMBER, like this:

    WITH got_next_e_date AS

    (

    SELECT id, eff_date, code1, code2

    MIN (CASE

    WHEN SUBSTR (code2, 2) = 'E '.

    THEN eff_date

    END

    ) OVER (PARTITION BY ID.

    , SUBSTR (code2, 1, 1)

    ORDER BY eff_date DESC

    ) AS next_e_date

    OF tab1

    )

    s AS

    (

    SELECT *.

    OF got_next_e_date

    "WHERE SUBSTR (code2, 2) s ="

    )

    e

    (

    SELECT *.

    OF got_next_e_date

    WHERE SUBSTR (code2, 2) = 'E '.

    )

    SELECT s.id

    s.eff_date

    s.code1

    s.code2

    e.id AS id_1

    e.eff_date AS eff_date_1

    e.code1 AS code1_1

    e.code2 AS code2_1

    S

    FULL OUTER JOIN e ON s.id = e.id

    AND s.next_e_date = e.eff_date

    AND SUBSTR (s.code2, 1, 1) = SUBSTR (e.code2, 1, 1)

    ORDER OF NVL (s.id, e.id)

    , NVL (SUBSTR (s.code2, 1, 1)

    , SUBSTR (e.code2, 1, 1)

    )

    s.eff_date

    ;

    Out (as you asked):

    ID EFF_DATE CODE1, CODE2 ID_1 EFF_DATE_1 CODE1_1 CODE2_1

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

    2 2015-01-14 DAT AS 2 AE DAT 2015-03-14

    2 2015-03-19 DAT AS 2 AE DAT 2015-04-18

    2 2015-08-28 DAT AS 2 AE DAT 2015-09-14

    2. DID DAT 2015-11-12

    2 AE DAT 2015-01-03

    2015-01-2 14 DAT BS 2 BE DAT 2015-05-14

    2015-02-2 14 DAT BS 2 BE DAT 2015-05-14

    2015 03-2 14 DAT BS 2 BE DAT 2015-05-14

    3. DID DAT 2015-09-16

    3 AE DAT 2015-04-16

    I guess code2 is always 2 characters, and the 2nd character is always ' or 'E '.

    I assume that the combination [id, eff_date, code2] is unique.

    If these assumptions are wrong, you need a few minor changes, but nothing big.

  • Join with count() question, please help!

    Hi all

    I have this problem (probably simple) that I can't solve... I have 2 tables (tbl_system_engineer and tbl_task_request) here... (only relevant columns are listed below)

    tbl_system_engineer
    -id NUMBER
    -full_name VARCHAR2

    tbl_task_request
    -tr_number NUMBER
    -submitted_on_date DATE (date of work was presented)
    -ass_comp_date DATE (date of task must be performed)
    -closed_date DATE (date of task was officially closed)
    -applicant NUMBER (the id of system engineer, the person who created this task)

    The request is meant to summarize how many of the tasks of engineers system is as follows:
    -"past completion date" - how many tasks have tbl_task_request.closed_date > tbl_task_request.ass_comp_date SYSDATE or > tbl_task_request.ass_comp_date for the engineer
    -' The completion Date approach' - how many tasks have a tbl_task_request.ass_comp_date in this month, but not "past date of completion" of the engineer
    -The calendar"- how many tasks have a tbl_task_request.ass_comp_date > the end of the month SYSDATE and year

    Result set lines are supposed to look like...
    'System engineer full name', after the completion date County, approaching County end date, the time count


    Help, please!

    Hello

    Welcome to the forum!

    This is an example of a Pivot , where you want to GROUP BY a combination of columns and some columns appear different, not different rows as columns.
    The way to do that is to GROUP BY the expressions for which you want to tidy and use CASE expressions for others.
    For example:

    SELECT       e.full_name
    ,       COUNT ( CASE
                   WHEN  r.closed_date     > r.xyz_comp_date
                   OR    SYSDATE          > r.xyz_comp_date
                   THEN  1
                  END
                )     AS overdue
    ,       COUNT ( CASE
                   WHEN  xyz.comp_date     <  ADD_MONTHS ( TRUNC(SYSDATE, 'MONTH')
                                                      , 1
                                             )
                   AND   r.closed_date     <= r.xyz_comp_date
                   AND   SYSDATE          <= r.xyz_comp_date
                   THEN  1
                  END
                )     AS approaching
    ,       COUNT ( CASE
                   WHEN  xyz.comp_date     >= ADD_MONTHS ( TRUNC(SYSDATE, 'MONTH')
                                                      , 1
                                             )
                   THEN  1
                  END
                )     AS on_schedule
    FROM       tbl_system_engineer     e
    JOIN       tble_task_request     r     ON     r.requestor     = e.id
    GROUP BY  e.full_name
    ;
    

    I do not have the versions of your tables, so I can't really test this. I suspect that some consideration for the NULL values must be added to the conditions of the CASE.
    If post you a small example data (CREATE TABLE and only relevant columns, INSERT statements) so people can test their ideas.

    Sometimes, especially when the columns are mutually exclusive, it is more simple calculate a value in a subquery, saying which column of output each line is associated with. That the calculated value is then used in the CASE expressions very simple in the main query,

    Among the features of this awkward site are ithat ir replaces what he thinks are naughty words with s.  I suspect that it happened in your message.  I guess that all of the columns with * are the same, for which I substituted above.

  • Inner join with an asymmetric column: plan not optimized SQL

    Hello

    I think that it is a FAQ, but I was unable to get a useful answer by Googling.

    Oracle version is 11.2.0 on Sparc64.

    Consider the following code:
    drop table x;
    PROMPT
    PROMPT Populate x with some users. Note the iduser PK
    PROMPT
    
    create table x as
    select 1 iduser, 'PUBLIC' owner from dual
    union
    select 2 iduser, 'SYSTEM' owner from dual
    union
    select 3 iduser, 'XDB' owner from dual
    union
    select 4 iduser, 'APPQOSSYS' owner from dual
    union
    select 5 iduser, 'SYS' owner from dual
    union
    select 6 iduser, 'OUTLN' owner from dual
    union
    select 7 iduser, 'DBSNMP' owner from dual
    /
    
    alter table x add constraint pk_x primary key(iduser);
    
    
    PROMPT
    PROMPT Create a table y from all_objects, but using the previous iduser 
    PROMPT as foreign key (owner column is not needed). Note the index
    PROMPT on column iduser
    PROMPT
    
    drop table y
    /
    create table y as
    select x.iduser, all_objects.*
    from all_objects, x
    where x.owner = all_objects.owner
    and x.owner in  ( 'PUBLIC', 'SYSTEM', 'XDB', 'APPQOSSYS',
        'SYS', 'OUTLN', 'DBSNMP')
    /
    alter table y drop column owner;
    alter table y add constraint y_fk foreign key(iduser) references x;
    create index idx_y on y(iduser);
    
    PROMPT
    PROMPT Take some stats. X stats are irrelevant, I think
    PROMPT
    exec dbms_stats.gather_table_stats( -
        USER, -
        'Y', -
        estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, -
        degree => DBMS_STATS.DEFAULT_DEGREE, -
        cascade => true, -
        method_opt => 'FOR COLUMNS IDUSER SIZE AUTO', -
        granularity => 'ALL' -
    )
    exec dbms_stats.gather_table_stats( -
        USER, -
        'X', -
        estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, -
        degree => DBMS_STATS.DEFAULT_DEGREE, -
        cascade => true, -
        method_opt => 'FOR COLUMNS IDUSER SIZE AUTO', -
        granularity => 'ALL' -
    )
    
    set autotrace trace exp
    
    PROMPT
    PROMPT APPQOSSYS has only 5 objects (well, your output may vary, but it should by
    PROMPT very similar), but the following query ignore the index and do a full scan on Y
    PROMPT
    select x.*, y.*
    from x, y
    where x.owner = 'APPQOSSYS'
    and y.iduser = x.iduser
    /
    
    PROMPT
    PROMPT Virtually, equivalent to the previous one. But the explain plan is very different
    PROMPT and the index is used
    PROMPT
    
    select y.*
    from x, y
    where x.owner = 'APPQOSSYS'
    and y.iduser = 4
    /
    
    set autotrace off
    The result is:
    ............................ [snip] .........................
    
    ( EXPLAIN PLAN OF FIRST QUERY)
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1702571549
    
    ---------------------------------------------------------------------------
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |      |   559 | 58136 |   142   (1)| 02:23:19 |
    |*  1 |  HASH JOIN         |      |   559 | 58136 |   142   (1)| 02:23:19 |
    |*  2 |   TABLE ACCESS FULL| X    |     1 |     9 |     2   (0)| 00:02:02 |
    |   3 |   TABLE ACCESS FULL| Y    | 55883 |  5184K|   139   (0)| 02:20:47 |
    ---------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - access("Y"."IDUSER"="X"."IDUSER")
       2 - filter("X"."OWNER"='APPQOSSYS')
    
    
    
    ( EXPLAIN PLAN OF SECOND QUERY)
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 2241001346
    
    -------------------------------------------------------------------------------------
    | Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    -------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |       |    10 |   950 |     2   (0)| 00:02:02 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| Y     |    10 |   950 |     2   (0)| 00:02:02 |
    |*  2 |   INDEX RANGE SCAN          | IDX_Y |    10 |       |     1   (0)| 00:01:01 |
    -------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       2 - access("Y"."IDUSER"=4)
    Well, the question is very simple: is it possible to get the first query to take the index and to avoid complete analysis? With no clues, of course.

    All of your advice and comments will be welcome. Thanks in advance.

    Best regards

    jjuanino wrote:

    Well, the question is very simple: is it possible to get the first query to take the index and to avoid complete analysis? With no clues, of course.

    All of your advice and comments will be welcome. Thanks in advance.

    This is a limit known optimizer - no realistic solution.

    The optimizer can recognize with the help of a histogram iduser on table column is very unevenly distributed, but there is not a generic strategy to recognize what owner on the table of X corresponds to what iduser on the table of Y.

    An approach that can help - even if I do not remember seeing documented is to rewrite the query with a subquery and use the / * + precompute_subquery * / tip.
    I have not tried with your data, but something like:

    select * from y
    where iduser in (
        select /*+ precompute_subquery */ x.iduser
        from x
        where owner = 'APPQSYS'
        )
    ;
    
    Regards
    Jonathan Lewis
    
    P.S.  Found a reference note by Tanel Poder: http://blog.tanelpoder.com/2009/01/23/multipart-cursor-subexecution-and-precompute_subquery-hint/
    
  • Firefox 18.0.2 aligns with full screen in Windows 7 (32 bit) even when I slide sideways. Anyone else seeing this?

    Windows 7 align on the net somewhere around 15 FF (FF drag window to the left or right edge of the desktop) has stopped working. FF now aligns only on the full screen. It's really a pain since I often have two Windows Open (FF at the request of the half, such as excel or outlook open in the other half). I keep hope it is fixed with the next version, but I see that this problems with 18.0.2.

    Safe mode is a good suggestion. Snap of half-screen FF has worked in safe mode. I then jumped back to normal mode and started disabling add until I figured out that you caused the problem (FindBar Tweak 0.5.5). All better now. Thank you!

  • How can satellite P500-024 - I do a new partition with full disk space?

    Hello

    I just bought the Satellite P500-024 and it came with 640 GB HARD drive.

    I just found when clicking on * my computer * which is the HARD drive is cut to the drive C: and D: drive. How can I add the D drive half of the HARD drive on the C: drive of priority so there because I then a full accese 640GO HDD in a chase without cutting 50-50?

    The reason why I ask this is because I noticed when I turn on the laptop it takes ages and maybe a bit slower due to the fact that it is half of the hard drive on drive C. So I want to know how it is easy to add them together into one so that I can get fast and pure to my new Satellite P500-024 performance.

    Thank you.

    Hi tagvic!

    First of all I must say that the two partitions have nothing to do with the slow start procedure on your laptop. Your laptop will be no faster if I you have only one partition, made it s! In addition, the second partition is required for Toshiba HDD recovery option. You know about it?

    HARD drive recovery option is really nice. You can restore factory in a few minutes. For it pour l' utiliser use go from the advanced boot menu, and then select Repair my computer. Then, you can select this option and follow the instructions on the screen. The first partition will be deleted, and after that it will have installed an image of factory settings. This means that you return to the same state that you started the laptop, the first time. The operating system preinstalled with already all the drivers and tools are installed.

    In my view, there is another reason for the slow start to the top. You should try to remove Toshiba Tempro. On my computer it causes a slow start too, and after removing the laptop started much faster.
    I can also recommend you to clean the system using CCleaner and defragment the HARD drive. Removal of startup programs folder that you don't need and try another program like AntiVir AntiVirus.

    I hope I could help a bit.

Maybe you are looking for

  • Question A100 - 01 Q satellite in combination with the Syncmaster 226BW

    HelloI need help. I have problems with "A100 - 01 Q" in combination with the Syncmaster 226BW, the problem seems to be the display driver, there is no new version available on toshiba.com. Would you mind and give me some advice? I need a new driver f

  • Yoga 8 sd card problem.

    Hi gus, thank you for allowing me to join the community. My Mrs had a 8 Yoga for Christmas and I found something a bit confusing. I tried to install a SD memory card in the slot micro sd on the back wall, but have you noticed the Virgin which is alre

  • Debugging starts with command line arguments?

    How to start the debugger to a program installation command line arguments? I've never had the need to do this before and I am puzzled as to how to do it now. I added a couple of command line arguments to control some run time options and I don't kno

  • Saved settings

    Recently, my screen was damaged as it is not displayed. But as I listen to the "rocket" on "random play all the" I could pretty much get to memorize a small part of the menu at startup music-> artists-> play all. The other day, however an independent

  • BlackBerry 10 - develop SPP (Obex) Server

    I develop an application that receives a file from bluetooth obex digitel pen (a device for which I can't write software). It would be ideal, if the application would receive the file bluetooth directly. For previous versions of firmware BlackBerry,