Join several Tables versioned

Hello

We are working on a data warehousing project and wonder how do to join several tables that each are versioned separately (type SCD 2 with a valid and valid to date).

Because for example, we get our client from a single source of information (id customer, name, etc.) and the information on the rate of customer from another source.  The sources are different, we have the separate tables for them and each of them gets versioned independently.

Here's my customer table (with its own valid and valuable to the columns).

IDName of the customerValid fromValid until the
1CitiBank1 JANUARY 14JANUARY 1, 15
1New CitiBank2 JANUARY 15FEBRUARY 1, 15
1Latest CitiBank2 FEBRUARY 15APRIL 1, 15

And similarly the Client side ID and rating information.

IDNoteValid fromValid until the
1Platinum1 JANUARY 14FEBRUARY 1, 14
1PremiumFEBRUARY 1, 141ST MARCH 15

I want to merge the two tables above and present information at a glance.  I have some difficulty to determine validates the valid columns.

IDName of the customerNoteValid from (Calculated)Valid until the (calculated)
1CitiBankPlatinum1 JANUARY 14FEBRUARY 1, 14
1CitiBankPremiumFEBRUARY 1, 14JANUARY 1, 15
1New CitiBankPremium2 JANUARY 15FEBRUARY 1, 15
1Latest CitiBankPremium2 FEBRUARY 151ST MARCH 15

And it's the query I used to get the above result:

SELECT client. id ,

       customer . name ,

       CRM . level ,

       Greatest (client. vld_fm , crm. vld_fm ),

       Least (client. vld_to , crm. vld_to )

DE    client client,

       client_rating crm

  client. id = crm. id

       AND ( client. vld_fm <= crm. vld_fm

             AND client. vld_fm <= crm. vld_to

             AND client. vld_fm >= crm. vld_fm

             AND client. vld_fm >= crm. vld_to )

        OR ( client. vld_fm BETWEEN crm. vld_fm AND crm. vld_to )

        OR ( client. vld_to BETWEEN crm. vld_fm AND crm. vld_to );



The problem is we have several data sources (and each with its own versions) and joins become so very very complex.  Is there a better way to write the query?

Or maybe a better way to design our tables?

Thanks for your help.

Anand

Hello

you only need ranges that overlap to join.

Re: How do to sql query in a loop

Is a simpler way to test if the x_start to x_stop range comes into conflict with the range of y_start to y_stop

WHERE     x_start <= y_stop AND     y_start <= x_stop

In other words, two overlapping if and only if everyone will start before the other ends one. If this is not obvious (and it was certainly not clear to me when I heard it), then look at it this way: two ranges are not overlapping if and only if one of them starts after the end of the other.

Concerning

Marcus

Tags: Database

Similar Questions

  • Outer Join and joining several Tables

    Hello

    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product

    I have three tables AddProject, AssociateProjectLead, AddAssociate. Now I'm generating a report who will join AddProject and AssociateProjectLead for a list of all the projects, even if it doenst have a project coordinator. I used the outer join for this. However, if I want the name of the project leader, I need to search for AddAssociate table. By joining this table also, the outer join is no longer valid. Please see the result below

    CREATE TABLE  "ADDPROJECT" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJID" VARCHAR2(20), 
         "PROJNAME" VARCHAR2(60), 
         "PROJSTARTDATE" DATE, 
         "PROJSTATUS" VARCHAR2(20), 
         "PROJENDDATE" DATE, 
         "PROJENDTYPE" VARCHAR2(20), 
         "PROJENDREASON" VARCHAR2(1000), 
         "UCPROJECTMANAGER" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "PARENTPROJID" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
          CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE
       )
    
    
    CREATE TABLE  "ADDASSOCIATE" 
       (     "VERSIONNO" NUMBER(*,0), 
         "ASSOCIATEID" NUMBER(9,0) NOT NULL ENABLE, 
         "ASSOCIATENAME" VARCHAR2(100) NOT NULL ENABLE, 
         "CTOJOINDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ENDDATE" DATE, 
         "SRCHFIELD" VARCHAR2(20), 
         "OPERATOR" VARCHAR2(20), 
         "FROMDATE" DATE, 
         "TODATE" DATE, 
          CONSTRAINT "PK_B23" PRIMARY KEY ("ASSOCIATEID") ENABLE
       )
    
    CREATE TABLE  "ASSOCIATEPROJECTLEAD" 
       (     "VERSIONNO" NUMBER(*,0), 
         "PROJLEADASSOID" NUMBER(9,0), 
         "PROJID" VARCHAR2(20), 
         "ASSOCIATEID" NUMBER(9,0), 
         "PROJLEADSTARTDATE" DATE, 
         "STATUS" VARCHAR2(20), 
         "ASSOCPROJHIDDENDATE" VARCHAR2(20), 
         "PROJHIDDENDATE" VARCHAR2(20), 
         "ENDDATE" DATE, 
          CONSTRAINT "PK_B40" PRIMARY KEY ("ASSOCIATEID", "PROJID", "ASSOCPROJHIDDENDATE") ENABLE
       )
    
    
    elect ap.projid,apl.associateid
    from addproject ap, associateprojectlead apl
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    
    
    PROJID ASSOCIATEID 
    Proj08 75825 
    Proj09 75825 
    Proj10 75825 
    Proj11 75825 
    Proj12 259811 
    Proj01 103035 
    Proj02 103035 
    Proj03 320092 
    Proj04 320092 
    Proj05 120974 
    Proj06 367393 
    Proj07 117618 
    Proj07 224882 
    Proj07 246652 
    prj001 -  
    prj001 -  
    
    16 rows returned in 0.00 seconds
    
    
    select ap.projid,apl.associateid,aa.associatename
    from addproject ap, associateprojectlead apl,addassociate aa
    where ap.projid = apl.projid(+)
    and ap.projhiddendate = apl.projhiddendate(+)
    and apl.associateid = aa.associateid
    
    
    PROJID ASSOCIATEID ASSOCIATENAME 
    Proj11 75825 Amarendra Kumar Singh 
    Proj10 75825 Amarendra Kumar Singh 
    Proj09 75825 Amarendra Kumar Singh 
    Proj08 75825 Amarendra Kumar Singh 
    Proj02 103035 Rajesh Jayaprakash 
    Proj01 103035 Rajesh Jayaprakash 
    Proj07 117618 Chetan Malhotra 
    Proj05 120974 Perumal Rajaram 
    Proj07 224882 Dilshad Ahmad 
    Proj07 246652 Shankar Kausley 
    Proj12 259811 Arunchandar Arun Vasan 
    Proj04 320092 Venkatesh Sarangan 
    Proj03 320092 Venkatesh Sarangan 
    Proj06 367393 Venkata Ramakrishna P 
    
    14 rows returned in 0.00 seconds
    How can I select all the values in table AddProject?

    Published by: Pramukh on August 23, 2012 12:18

    Hello

    I could get the result with a bit of modification

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    

    As a follow-up, I have a request more. In the report form, the user can select a particular project ID and the report should be generated as a result. For example;-he wants to see the results of the only "Proj08". I get the output as below, while the result should display only the details of 'Proj08 '.

    select ap.projid,
           apl.associateid,
           aa.associatename
      from addproject ap
           left outer join
           associateprojectlead apl
        on ap.projid = apl.projid
       and ap.projhiddendate = apl.projhiddendate
       and ap.projID = 'Proj08'
           left outer join
           addassociate aa
        on apl.associateid = aa.associateid
    ORDER BY ap.projID
    
    PROJID ASSOCIATEID ASSOCIATENAME
    Proj01 -  -
    Proj02 -  -
    Proj03 -  -
    Proj04 -  -
    Proj05 -  -
    Proj06 -  -
    Proj07 -  -
    Proj08 75825 Amarendra Kumar Singh
    Proj09 -  -
    Proj10 -  -
    Proj11 -  -
    Proj12 -  -
    prj001 -  -
    prj001 -  -  
    
  • joining several tables to generate data

    with itemlist as

    (select 1 cid, listname 'test', 'r' flg Union double all the)

    Select 2 cid, listname 'test2', ' not flg double

    ),

    category 1)

    Select 1 cid, 122 k' sub '123' catcode, of any double Union

    Select 1 cid, '234i' catcode, sub '124' all Union double

    Select 1 cid, 238 k' void '124' catcode, double

    )

    void)

    Select 1 cid, sub '123' of any union double

    Select 1 cid, sub ' 124' double

    )

    I want to write a static query that gathers all the tables and produces the following output assuming that

    CID is you pass as a parameter

    CID listname flg topic catcode

    1 123 122 k r test

    1 test of r 234i 124

    1 124 238 k r test

    Suppose the data as changes to follow and even cid 1 is to pass as a parameter:

    with itemlist as

    (select 1 cid, listname 'test', 'r' flg Union double all the)

    Select 2 cid, listname 'test2', ' not flg double

    ),

    category 1)

    Select 1 cid, 122 k' sub '123' catcode, of any double Union

    Select 1 cid, '234i' catcode, sub '124' all Union double

    Select 1 cid, 238 k' void '124' catcode, double

    )

    void)

    Select 2 cid, sub '123' of any union double

    Select 2 cid, sub '124' double

    )

    then the output should be

    CID listname flg topic catcode

    1 r test 123

    1 test of r 124

    1 test of r 124

    for a final example, suppose the data now as to user 1 as cid

    with itemlist as

    (select 1 cid, listname 'test', 'r' flg Union double all the)

    Select 2 cid, listname 'test2', ' not flg double

    ),

    category 1)

    Select 2 cid, 122 k' sub '123' catcode, of any double Union

    Select 2 cid, catcode '234i', '124' void in any union double

    Select 2 cid, 238 k' void '124' catcode, double

    )

    void)

    Select 1 cid, sub '123' of any union double

    Select 2 cid, sub '124' double

    )

    output must be

    CID listname flg topic catcode

    1       test            r                 123

    Basically, the user will pass a cid, in this case 1. I'll read the itemlist where cid = 1 and I want to join all the other tables

    to itemlist in such a way that I can generate extra lines.  If no entry is found for cid 1, for example, in category 1 or auxiliary table

    then the beloging column of this table must be null in the result

    can someone help me write a query to produce the output above

    Hello

    elmasduro wrote:

    ...

    Here is an explanation of the output.  a user will have a front screen where it can enter itemlist info.
    then in a submenu may enter a category or sub or both or none of them. the user can select multiple categories or sub
    When the user presses the button Save, an entry will be made in the itemlist table, for example the cid = 1.
    If he choose a category but without Subs, then will be entered into the table at say cid = 1


    but no entries will be made for sub because he chose not to all values.  If he chooses void instead of category values
    then sub taable will fill and category is not. If he chooses the category and under, then both will be filled.

    what I want to do is to join the itemlist with table category and sub table and get the data to the Scriptures, this intervention of the user.
    These entries not found will be the null value column in the result.
    for example, the cid = 1 itemlist, if user enter category but not void, itemlist will be the join with the table category and sub
    but since sub has no entry for the cid = 1, the column object will be empty in the output, but catcode will fill

    I'm so confused.

    It is a query (that is, just a SELECT statement, which shows the data already present in the tables), or is this a DML statement, that will add data to the tables?  If it's just a query, then do not say things like "entries will be taken" or "filled with tables.

    Assuming you want a request maybe you want something like this:

    WITH c_and_s AS

    (

    SELECT NVL (c.cid, s.cid) AS cid

    NVL (c.sub, s.sub) AS topic

    , NVL2 (s.cid, c.catcode, NULL) AS catcode

    CATEGORY 1 c

    FULL OUTER JOIN void s ON c.cid = s.cid

    AND c.sub = s.sub

    )

    SELECT i.cid, i.listname, i.flg

    cs.subject, cs.catcode

    Itemlist I have

    LEFT OUTER JOIN c_and_s ON cs.cid = i.cid cs

    WHERE the i.cid (1) - you can do the cids 2 or several at the same time, if you want to

    ORDER BY i.cid, cs.subject, cs.catcode

    ;

    This example gets the output you asked data sample you posted.

  • Joining several tables in Oracle DB

    I have the following tables.

    1 AddProject
    -PROJID
    -projName
    2 AddLab
    -Labrador
    -teacher
    3 ProjLabAssociation
    -PROJID
    -Labrador
    4 AddResearchArea
    -raID
    -raName
    5 ProjRAAssociation
    -PROJID
    -raID


    AddProject is associated with tables-AddLab and AddResearchArea
    ProjLabAssociation and ProjRAAssociation are the association of the tables that contain the primary key of the corresponding tables. The two fields in these 2 tables are primary keys.

    If AddProject has 3 entrances - (Proj1, ProjectA) (Proj2 ProjectB), (Proj3, ProjectC)
    AddLab has 2 entrances - (Lab1, Bangalore), (Lab2, Chennai)
    AddResearchArea has 2 inputs - AM1 (Green Computing) (RA2, Cloud Computing)

    ProjLabAssociation has 2 entrances - (Proj2 Lab1), (Proj3, Lab1)
    ProjRAAssociation has 3 entries - (Proj2 RA1), (Proj3, AM1), (Proj3, RA2)


    If I ask by AddLab given for (Lab1, Bangalore), I should get the following columns in the result table
    --------------------------------------------------------------------------------------------------------------------------------
    Table2ID | Table2Name | Table3ID | Table3Name | Table1ID | Table1Name
    Lab1. Bangalore | RA1 | Green Computing | Proj2 | Project b
    Lab1. Bangalore | RA1 | Green Computing | Proj3 | Project c
    Lab1. Bangalore | RA2 | Cloud Computing | Proj3 | Project c
    --------------------------------------------------------------------------------------------------------------------------------

    I tried the following commands but I m getting the expected result

    1.
    SELECT * FROM AddLab al, ProjLabAssociation pl, AddProject ap WHERE al.labID = pl.labID(+) and ap.projID = pl.projID(+);
    A SQLException exception is thrown by saying - java.sql.SQLException: ORA-01417: a table can be external joined as another table

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

    2.
    SELECT * FROM AddLab,AddProject,AddResearchArea WHERE labID in 
    (select al.labID from ProjLabAssociation pl,AddLab al  where al.labID = pl.labID)
    AND projID in
    (select ap.projID from ProjLabAssociation pl,Addproject ap where ap.projID = pl.projID)
    AND themeID in 
    (select ar.raID from ProjRAAssociation pr, AddResearchArea ar where ar.raID = pr.raID)
    AND projID in
    (select ap.projID from ProjRAAssociation pr,Addproject ap where ap.projID = pr.projID)
    ORDER BY labID;
    I do not get results expcted here

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

    Oracle version: 9i 10g / 11g

    Can anyone help me in this.

    Published by: user9205634 on December 22, 2011 03:40

    Hello

    Below the code gives the result

    with table1 as
    (
    select 'Proj1' as table1id,'ProjectA' as table1name from dual
    union all
    select 'Proj2' as table1id,'ProjectB' as table1name from dual
    union all
    select 'Proj3' as table1id,'ProjectC' as table1name from dual
    union all
    select 'Proj4' as table1id,'ProjectD' as table1name from dual
    )
    ,table2 as
    (
    select 'Lab1' as table2id,'Bangalore' as table2name from dual
    union all
    select 'Lab2' as table2id,'Chennai' as table2name from dual
    union all
    select 'Lab3' as table2id,'Delhi' as table2name from dual
    )
    , table3 as
    (
    select 'RA1' as table3id,'Green Computing' as table3name from dual
    union all
    select 'RA2' as table3id,'Cloud Computing' as table3name from dual
    )
    ,table1table2 as
    (
    select 'Proj2' as table1id,'Lab1' as table2id from dual
    union all
    select 'Proj3' as table1id,'Lab1' as table2id from dual
    union all
    select 'Proj3' as table1id,'Lab2' as table2id from dual
    union all
    select 'Proj4' as table1id,'Lab3' as table2id from dual
    )
    ,table1table3 as
    (
    select 'Proj2' as table1id,'RA1' as table3id from dual
    union all
    select 'Proj3' as table1id,'RA1' as table3id from dual
    union all
    select 'Proj3' as table1id,'RA2' as table3id from dual
    )
    select t2.table2id,t2.table2name,t3.table3id,t3.table3name,t1.table1id,t1.table1name
    from table1 t1,table2 t2,table3 t3,table1table2 jt1t2,table1table3 jt1t3
    where
    jt1t2.table2id=t2.table2id and
    t1.table1id=jt1t2.table1id and
    jt1t3.table1id(+)=jt1t2.table1id and
    t3.table3id(+)=jt1t3.table3id
    order by t2.table2name,t3.table3id;
    
    TABLE2ID TABLE2NAME TABLE3ID TABLE3NAME      TABLE1ID TABLE1NAME
    -------- ---------- -------- --------------- -------- ----------
    Lab1     Bangalore  RA1      Green Computing Proj2    ProjectB
    Lab1     Bangalore  RA1      Green Computing Proj3    ProjectC
    Lab1     Bangalore  RA2      Cloud Computing Proj3    ProjectC
    Lab2     Chennai    RA1      Green Computing Proj3    ProjectC
    Lab2     Chennai    RA2      Cloud Computing Proj3    ProjectC
    Lab3     Delhi                               Proj4    ProjectD   
    
     6 rows selected 
    

    Kind regards
    Prabhu

  • Retriving data by joining several tables and total general

    Hello PL/SQL gurus and experts.

    I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
    I have table-

    I have the following three tables
    DROP TABLE Person_Tb;
    create table Person_Tb(Person_ID,Person_FName,Person_LName) as select
    1001, 'Nikki','Carlos' from dual union all select
    1002, 'Nina', 'Harrison' from DUAL union all select
    1003, 'Mike', 'Carwely' from dual union all select
    1004, 'Michael', 'Robinson' from DUAL union all select
    1005, 'Hendi', 'Klum' from dual union all select
    1006, 'Robert', 'Regan' from dual union all select
    1007, 'Maria', 'Washington' from dual union all select
    1008, 'Kistrien', 'Obama' from dual union all select
    1009, 'Andrew', 'Regan' from dual union all select
    1010, 'Emma', 'Thomsan' from dual union all select
    1011, 'Andy', 'Grant' from dual union all select
    1012, 'Brandy', 'Decosta' from dual;
    DROP TABLE Teacher;
    create table Teacher(Teacher_ID,Fee_Date,Account_ID) as select
    1001, '04/04/2013',3004 from dual union all select
    1002, '04/06/2013',3006 from DUAL union all select
    1003, '04/08/2013',3014 from dual union all select
    1004, '04/08/2013',3017 from DUAL union all select
    1005, '04/09/2013',3019 from dual union all select
    1011, '04/12/2013',3025 from dual union all select
    1012, '04/12/2013',3046 from DUAL;
    DROP TABLE Student;
    create table Student(Student_ID,Subaccount_ID) as select
    1006,3004 from dual union all select
    1007,3006 from DUAL union all select
    1008,3004 from dual union all select
    1009,3017 from DUAL union all select
    1010,3017 from dual;
    I am able to recover the data individually Tracher and student as -.
    Select distinct pt.Person_LName || ',' ||
                                           pt.Person_FName Trdr_NM
                                      from Student st, person_Tb pt
                                     where st.Student_id = pt.PERSON_ID
    Select distinct pt.Person_LName || ',' ||
                                           pt.Person_FName SubAct_Invst
                                      from Teacher  tc, person_Tb pt
                                     where tc.teacher_id = pt.PERSON_ID
    I need to get the records for all teachers who are associated with students-
    SubAct_Invst     Trdr_NM
    ----------------------------------------------------
    Carlos,Nikki 
              Regan,Robert
              Obama,Kistrien
    Harrison,Nina
              Washington,Maria
    Carwely,Mike
    Robinson,Michael
              Regan,Andrew
              Thomsan,Emma
    Klum,Hendi
    Grant,Andy
    Decosta,Brandy
    ------------------------------------------------------
    Grand Total
    7                                5
    But how to retrieve the data above format, many want to help. Thanks in advance and I really appericate your time and efforts.

    Ideally, your condition must be handled by a front-end tool...

    If you need specifically using SQL, you can check my previous post...

  • Problem with joining several tables

    Hello PL/SQL gurus and experts.

    I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
    I followed two tables

    Student-
    drop table TT3;
    create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    1,11,21,'Mike',27 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual union all select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    1,11,21,'Mike',27 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual ;
    Fees-
    drop table TT4;
    create table TT4(FeesCntlr,CommCntlr,LatePayCntlr,Fees,Commission,Latepayment) as select
    1,11,21,25000,4456,223 from dual union all select
    2,12,22,356000,3321,0 from dual union all select
    1,11,21,456000,223,33 from dual union all select
    4,17,27,32890,0,0 from dual union all select
    5,13,21,0,778,223 from dual union all select
    6,14,24,332567,222,0 from dual union all select
    7,15,25,228990,22,0 from dual union all select
    8,16,26,0,0,2234 from dual union all select
    1,11,21,22345,0,0 from dual union all select
    2,12,22,2222789,2,33 from dual union all select
    1,11,21,334567,0,0 from dual union all select
    4,17,27,9987250,2,33 from dual union all select
    5,13,21,2227890,0,0 from dual union all select
    6,14,24,2278231,0,3345 from dual union all select
    7,15,25,223456,2,0 from dual union all select
    8,16,26,223890,0,0 from dual ;
    I am looking forward to the fees, commissions and surcharges output for each student and by using the following SQL code.
    select t3.Name,t3.age,t4.Fees
    from tt3 t3, tt4 t4
    where t3.FeesCntlr=t4.FeesCntlr
    union
    select t3.Name,t3.age,t4.Commission
    from tt3 t3, tt4 t4
    where t3.CommCntlr=t4.CommCntlr
    union
    select t3.Name,t3.age,t4.Latepayment
    from tt3 t3, tt4 t4
    where t3.LatePayCntlr=t4.LatePayCntlr
    but it gives me not the correct result and showing a lot of entries and display only the "Expenses" column then only I'm looking for the output to be -
    Name     Age     Fees          Commission     Laypayment
    Mike     25     837912          4679          256
    Clark     26     2578789          3323          33
    Ussan     36     10020140     2          33
    Linda     38     2227890          778          223
    Obrek     38     2610798          222          3345
    Batty     32     452446          24          0
    Nicky     23     223890          0          2234
    Kindly help me with this. Thank you in advance for your time and effort.

    Hello

    I see your table TT3 has duplicated lines. A reason for this?

    Rather than run a separate, I created it without duplicated lines:

    create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual;
    
    create table TT4(FeesCntlr,CommCntlr,LatePayCntlr,Fees,Commission,Latepayment) as select
    1,11,21,25000,4456,223 from dual union all select
    2,12,22,356000,3321,0 from dual union all select
    1,11,21,456000,223,33 from dual union all select
    4,17,27,32890,0,0 from dual union all select
    5,13,21,0,778,223 from dual union all select
    6,14,24,332567,222,0 from dual union all select
    7,15,25,228990,22,0 from dual union all select
    8,16,26,0,0,2234 from dual union all select
    1,11,21,22345,0,0 from dual union all select
    2,12,22,2222789,2,33 from dual union all select
    1,11,21,334567,0,0 from dual union all select
    4,17,27,9987250,2,33 from dual union all select
    5,13,21,2227890,0,0 from dual union all select
    6,14,24,2278231,0,3345 from dual union all select
    7,15,25,223456,2,0 from dual union all select
    8,16,26,223890,0,0 from dual ;
    
      SELECT t3.name, t3.age, SUM (t4.fees) fees, SUM (t4.commission) commission
           , SUM (t4.latepayment) latepayment
        FROM tt3 t3, tt4 t4
       WHERE     t3.feescntlr = t4.feescntlr
             AND t3.commcntlr = t4.commcntlr
             AND t3.latepaycntlr = t4.latepaycntlr
    GROUP BY t3.name, t3.age;
    
    Output:
    NAME         AGE       FEES COMMISSION LATEPAYMENT
    ----- ---------- ---------- ---------- -----------
    Mike          25     837912       4679         256
    Ussan         28   10020140          2          33
    Linda         29    2227890        778         223
    Clark         26    2578789       3323          33
    Obrek         35    2610798        222        3345
    Nicky         38     223890          0        2234
    Batty         45     452446         24           0
    

    Kind regards.
    Al

    Published by: Alberto Faenza on November 6, 2012 12:40

  • How to join several tables source and do the research?

    I have a requirement to load a target table by joining 4 source tables. Also, I do a search on a field of table to transform codes and check for NULL values. What will be the best approach for load table target?
    Is it possible to do it in a single interface, or do I need to create multiple interfaces to achieve this?

    My basic source and target are oracle, and I am planing to use incremental update Oracle merge.

    Thank you

    You are in the right direction by creating an interface for this transformation.
    You will need to drag the source drop 4 tables + the lookup table in the Sources of Interface window and then make the appropriate joins.
    Also, look for NULL values in the transformation. Depends on what you want to do with NULL values. If you want to ignore, use a filter.
    If you want to make mistakes, use a constraint.
    If you want to convert them, use NVL

    Start with Oracle Update incremental and once successful, use incremental update Oracle MERGE.

  • Join several tables of two different patterns - is it possible?

    If this is the case, what are the measures?

    THX

    This is the case.

    You must prefix the tables with the schemaname tables is in, or create a synonym for the table. In addition, you must grant select rights from of a the reference schema owner schema:

    SELECT A.*,B.*
      FROM SCHEMA1.TEST_TABLE A,
           SCHEMA2.TEST_TABLE B
     WHERE somecondition
    
  • Create a trigger instead of update several tables in a view

    Dear everybody

    I am trying to create a trigger that updates instead of to day joined several tables in a view, but I can't get my trigger to work. The create view command was as follows:
    CREATE OR REPLACE VIEW VIEW_MI_JOIN_GC
    AS
    SELECT MAP_INDEX.mi_prinx,
           index_type_id,
           original_map_publication_id,
           original_map_sheet_number_id,
           name_of_feature,
           geog_coordinates_id,
           GEOG_COORDINATES.mi_prinx AS "mi_prinx_polygon",
           GEOG_COORDINATES.geographical_coordinates,
           GEOG_COORDINATES.mapinfo_style_row
     FROM MAP_INDEX
      JOIN GEOG_COORDINATES
       ON geog_coordinates_id=GEOG_COORDINATES.mi_prinx;
    The view above connects a polygon table to the table of function names which means that a polygon appears several times in a view, even though one version of the polygon exists in the base table. This means the direct update of view cannot take place, since 1 polygon can appear multiple times in a view. The two original base tables and their columns names are:
    MAP_INDEX
    ---------
    MI_PRINX
    INDEX_TYPE_ID
    ORIGINAL_MAP_PUBLICATION_ID
    ORIGINAL_MAP_SHEET_NUMBER_ID
    NAME_OF_FEATURE
    MAPINFO_STYLE_ROW
    GEOGRAPHICAL_COORDINATES
    GEOG_COORDINATES_ID
    
    GEOG_COORDINATES
    ----------------
    MI_PRINX
    GEOGRAPHICAL_COORDINATES
    MAPINFO_STYLE_ROW
    Relax, I created was as follows:
    CREATE OR REPLACE TRIGGER TRIG_VIEW_MI_JOIN_GC
       INSTEAD OF UPDATE ON VIEW_MI_JOIN_GC
          REFERENCING NEW AS NEW
     FOR EACH ROW
    BEGIN
     UPDATE MAP_INDEX
      SET mi_prinx = :NEW.mi_prinx,
          index_type_id = :NEW.index_type_id,
          original_map_publication_id = :NEW.original_map_publication_id,
          original_map_sheet_number_id = :NEW.original_map_sheet_number_id,
          name_of_feature = :NEW.name_of_feature,
          mapinfo_style_row = :NEW.mapinfo_style_row,
          geographical_coordinates = :NEW.geographical_coordinates,
          geog_coordinates_id = :NEW.geog_coordinates_id
       WHERE geog_coordinates_id = :OLD.geog_coordinates_id;
     UPDATE GEOG_COORDINATES
      SET mi_prinx = :NEW.mi_prinx,
          geographical_coordinates = :NEW.geographical_coordinates,
          mapinfo_style_row = :NEW.mapinfo_style_row
       WHERE mi_prinx = :OLD.mi_prinx;
    END;
    /
    The idea is that when I draw a new polygon in MapInfo and assign him a revised number geog_coordinates_id and the number of mi_prinx_polygon, which are the same, once I have save the view as then it updates the underlying tables. Geographical_coordinates and mapinfo_style_row of map_index table columns are columns with ancient polygon data which while not having currently new data inserted into them, are required for the previous data they contain. These data are currently being added to the geog_coordinates table with other scripts. The idea is that all the data is then read using a view and updates made to the view, triggering instead of relaxing, so data are not duplicated but still visible as if it were.

    When I created first the relaxation above in SQLdeveloper it seems to run constantly. Then my computer crashed, not related to this work, and I lost session because I did not commit it. I was not ready to commit it because I believe that something is wrong.

    I am in the trigger syntax correctly and I go about it in the right way? I want to only update the rows that have changed, that's why I was using: NEWS and: OLD.

    Kind regards

    Tim

    Published by: user467357 on November 18, 2008 18:07
    I modified my script a little because there were a few errors. for example. start and old as old and view name typo

    Something like this->

    satyaki>
    satyaki>select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    
    Elapsed: 00:00:01.78
    satyaki>
    satyaki>
    satyaki>create table MAP_INDEX
      2   (
      3        mi_prinx                    NUMBER(10) not null,
      4        index_type_id                NUMBER(6) not null,
      5        original_map_publication_id  NUMBER(6) not null,
      6        original_map_sheet_number_id NUMBER(6) not null,
      7        name_of_feature              VARCHAR2(80) not null,
      8        mapinfo_style_row            VARCHAR2(80),
      9        geographical_coordinates    SDO_GEOMETRY,
     10        geog_coordinates_id          NUMBER(10),
     11        constraints pk_mi_prinx primary key(mi_prinx)
     12   );
    
    Table created.
    
    Elapsed: 00:00:04.39
    satyaki>
    satyaki>create table GEOG_COORINDATES
      2   (
      3     mi_prinx NUMBER(10) not null,
      4     geographical_coordinates SDO_GEOMETRY,
      5     mapinfo_style_row VARCHAR2(80),
      6     constraints pk_mi_prinx_n primary key(mi_prinx)
      7   );
    
    Table created.
    
    Elapsed: 00:00:00.30
    satyaki>
    satyaki>
    satyaki>CREATE OR REPLACE VIEW VIEW_MI_JOIN_GC
      2  AS
      3  SELECT MAP_INDEX.mi_prinx,
      4         MAP_INDEX.index_type_id,
      5         MAP_INDEX.original_map_publication_id,
      6         MAP_INDEX.original_map_sheet_number_id,
      7         MAP_INDEX.name_of_feature,
      8         MAP_INDEX.geog_coordinates_id,
      9         GEOG_COORINDATES.mi_prinx AS "mi_prinx_polygon",
     10         GEOG_COORINDATES.geographical_coordinates,
     11         GEOG_COORINDATES.mapinfo_style_row
     12   FROM MAP_INDEX , GEOG_COORINDATES
     13   WHERE MAP_INDEX.geog_coordinates_id=GEOG_COORINDATES.mi_prinx;
    
    View created.
    
    Elapsed: 00:00:00.32
    satyaki>
    satyaki>
    satyaki>insert into MAP_INDEX values(
      2                                 &mi_prinx,
      3                                 &index_type_id,
      4                                 &original_map_publication_id,
      5                                 &original_map_sheet_number_id,
      6                                 '&name_of_feature',
      7                                 '&mapinfo_style_row',
      8                                 null,
      9                                 &geog_coordinates_id);
    Enter value for mi_prinx: 1
    old   2:                                &mi_prinx,
    new   2:                                1,
    Enter value for index_type_id: 44
    old   3:                                &index_type_id,
    new   3:                                44,
    Enter value for original_map_publication_id: 5678
    old   4:                                &original_map_publication_id,
    new   4:                                5678,
    Enter value for original_map_sheet_number_id: 356
    old   5:                                &original_map_sheet_number_id,
    new   5:                                356,
    Enter value for name_of_feature: AA
    old   6:                                '&name_of_feature',
    new   6:                                'AA',
    Enter value for mapinfo_style_row: GG
    old   7:                                '&mapinfo_style_row',
    new   7:                                'GG',
    Enter value for geog_coordinates_id: 9
    old   9:                                &geog_coordinates_id)
    new   9:                                9)
    
    1 row created.
    
    Elapsed: 00:00:00.16
    satyaki>/
    Enter value for mi_prinx: 2
    old   2:                                &mi_prinx,
    new   2:                                2,
    Enter value for index_type_id: 55
    old   3:                                &index_type_id,
    new   3:                                55,
    Enter value for original_map_publication_id: 6789
    old   4:                                &original_map_publication_id,
    new   4:                                6789,
    Enter value for original_map_sheet_number_id: 357
    old   5:                                &original_map_sheet_number_id,
    new   5:                                357,
    Enter value for name_of_feature: BB
    old   6:                                '&name_of_feature',
    new   6:                                'BB',
    Enter value for mapinfo_style_row: 10
    old   7:                                '&mapinfo_style_row',
    new   7:                                '10',
    Enter value for geog_coordinates_id: 8
    old   9:                                &geog_coordinates_id)
    new   9:                                8)
    
    1 row created.
    
    Elapsed: 00:00:00.04
    satyaki>
    satyaki>commit;
    
    Commit complete.
    
    Elapsed: 00:00:00.03
    satyaki>
    satyaki>
    satyaki>insert into GEOG_COORINDATES values(&mi_prinx,null,'&mapinfo_style_row');
    Enter value for mi_prinx: 9
    Enter value for mapinfo_style_row: FFG
    old   1: insert into GEOG_COORINDATES values(&mi_prinx,null,'&mapinfo_style_row')
    new   1: insert into GEOG_COORINDATES values(9,null,'FFG')
    
    1 row created.
    
    Elapsed: 00:00:00.07
    satyaki>/
    Enter value for mi_prinx: 8
    Enter value for mapinfo_style_row: GGT
    old   1: insert into GEOG_COORINDATES values(&mi_prinx,null,'&mapinfo_style_row')
    new   1: insert into GEOG_COORINDATES values(8,null,'GGT')
    
    1 row created.
    
    Elapsed: 00:00:00.05
    satyaki>
    satyaki>commit;
    
    Commit complete.
    
    Elapsed: 00:00:00.02
    satyaki>
    satyaki>select * from VIEW_MI_JOIN_GC;
    
      MI_PRINX INDEX_TYPE_ID ORIGINAL_MAP_PUBLICATION_ID ORIGINAL_MAP_SHEET_NUMBER_ID NAME_OF_FEATURE                                                                  GEOG_COORDINATES_ID mi_prinx_polygon GEOGRAPHICAL_COORDINATES(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    ---------- ------------- --------------------------- ---------------------------- -------------------------------------------------------------------------------- ------------------- ---------------- ---------------------------------------------------------------------------------------------------------------
             1            44                        5678                          356 AA                                                                                                 9                9
             2            55                        6789                          357 BB                                                                                                 8                8                                                                                                                 
    
    Elapsed: 00:00:00.09
    satyaki>
    satyaki>
    satyaki>CREATE OR REPLACE TRIGGER TRIG_VIEW_MI_JOIN_GC
      2  INSTEAD OF UPDATE ON VIEW_MI_JOIN_GC
      3  FOR EACH ROW
      4  DECLARE
      5   m_info_svw  varchar2(80);
      6  BEGIN
      7   m_info_svw :=  :NEW.mapinfo_style_row;
      8
      9   UPDATE MAP_INDEX
     10    SET mi_prinx = :NEW.mi_prinx,
     11        index_type_id = :NEW.index_type_id,
     12        original_map_publication_id = :NEW.original_map_publication_id,
     13        original_map_sheet_number_id = :NEW.original_map_sheet_number_id,
     14        name_of_feature = :NEW.name_of_feature,
     15        mapinfo_style_row = m_info_svw,
     16        geographical_coordinates = :NEW.geographical_coordinates,
     17        geog_coordinates_id = :NEW.geog_coordinates_id
     18     WHERE geog_coordinates_id = :OLD.geog_coordinates_id;
     19   UPDATE GEOG_COORINDATES
     20    SET mi_prinx = :NEW.geog_coordinates_id,
     21        geographical_coordinates = :NEW.geographical_coordinates,
     22        mapinfo_style_row = m_info_svw
     23     WHERE mi_prinx = :OLD.geog_coordinates_id;
     24  END;
     25  /
    
    Trigger created.
    
    Elapsed: 00:00:00.20
    satyaki>
    satyaki>select * from VIEW_MI_JOIN_GC;
    
      MI_PRINX INDEX_TYPE_ID ORIGINAL_MAP_PUBLICATION_ID ORIGINAL_MAP_SHEET_NUMBER_ID NAME_OF_FEATURE                                                                  GEOG_COORDINATES_ID mi_prinx_polygon GEOGRAPHICAL_COORDINATES(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    ---------- ------------- --------------------------- ---------------------------- -------------------------------------------------------------------------------- ------------------- ---------------- ---------------------------------------------------------------------------------------------------------------
             1            44                        5678                          356 CC                                                                                                 9                9
             2            55                        6789                          357 BB                                                                                                 8                8                                                                                                                 
    
    Elapsed: 00:00:00.09
    satyaki>
    satyaki>select mi_prinx,mapinfo_style_row from GEOG_COORINDATES;
    
      MI_PRINX MAPINFO_STYLE_ROW
    ---------- --------------------------------------------------------------------------------
             9 FFG
             8 GGT
    
    Elapsed: 00:00:00.07
    satyaki>select * from MAP_INDEX;
    
      MI_PRINX INDEX_TYPE_ID ORIGINAL_MAP_PUBLICATION_ID ORIGINAL_MAP_SHEET_NUMBER_ID NAME_OF_FEATURE                                                                  MAPINFO_STYLE_ROW                                                                GEOGRAPHICAL_COORDINATES(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), S
    ---------- ------------- --------------------------- ---------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------
             1            44                        5678                          356 CC                                                                               HHH
             2            55                        6789                          357 BB                                                                               HHH                                                                                                                                                  
    
    Elapsed: 00:00:00.12
    satyaki>
    satyaki>update VIEW_MI_JOIN_GC
      2    set name_of_feature = 'DD'
      3  where mi_prinx = 1;
    
    1 row updated.
    
    Elapsed: 00:00:00.05
    satyaki>
    satyaki>select * from VIEW_MI_JOIN_GC;
    
      MI_PRINX INDEX_TYPE_ID ORIGINAL_MAP_PUBLICATION_ID ORIGINAL_MAP_SHEET_NUMBER_ID NAME_OF_FEATURE                                                                  GEOG_COORDINATES_ID mi_prinx_polygon GEOGRAPHICAL_COORDINATES(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    ---------- ------------- --------------------------- ---------------------------- -------------------------------------------------------------------------------- ------------------- ---------------- ---------------------------------------------------------------------------------------------------------------
             1            44                        5678                          356 DD                                                                                                 9                9
             2            55                        6789                          357 BB                                                                                                 8                8                                                                                                                 
    
    Elapsed: 00:00:00.08
    satyaki>
    satyaki>select mi_prinx,mapinfo_style_row from GEOG_COORINDATES;
    
      MI_PRINX MAPINFO_STYLE_ROW
    ---------- --------------------------------------------------------------------------------
             9 FFG
             8 GGT
    
    Elapsed: 00:00:00.06
    satyaki>
    satyaki>update VIEW_MI_JOIN_GC
      2     set mapinfo_style_row = 'OOOO'
      3     where mi_prinx = 1;
    
    1 row updated.
    
    Elapsed: 00:00:00.05
    satyaki>
    satyaki>select mi_prinx,mapinfo_style_row from GEOG_COORINDATES;
    
      MI_PRINX MAPINFO_STYLE_ROW
    ---------- --------------------------------------------------------------------------------
             9 OOOO
             8 GGT
    
    Elapsed: 00:00:00.06
    satyaki>
    satyaki>select mapinfo_style_row from MAP_INDEX;
    
    MAPINFO_STYLE_ROW
    --------------------------------------------------------------------------------
    OOOO
    HHH
    
    Elapsed: 00:00:00.06
    satyaki>
    

    Hope this will help you.

    Kind regards.

    LOULOU.

  • Outer join, 3 tables

    Please see the attached link for table structures and data of the sample.

    There will be several lines in the table of SALES with different SALETYPEs. There may be several lines in the table RETURNS, corresponding to some of the points of SALE. RETURNS the table has a foreign key to the SALE. The report that I am trying to generate with a select sql statement must include a line for each type of sale (from table SALETYPE) and the sum of sale amounts corresponding to this type of sale of the SALES table. The table may not return the entries for all types of sales and the amount of Scripture must be reported as zero. The SQL I use is below, but does not work. I hope that I have explained this correctly. Please see the doc attached for typical data that I work with. Can someone please?

    https://spreadsheets.Google.com/pub?key=0AnDmnUJXOChwdGF2ZjdjdHFtMGF1MkJ3MWtjQ2JfUmc & hl = in & Single = true & gid = 0 & output = html

    Select SUM (s.amount) as sum_amount, t.sale_type from SALES s, SALETYPE t, r RETURNS
    where s.id = r.id
    and s.sale_type_id = t.id
    T.sale_type group;

    Published by: 801941 on October 12, 2010 15:02

    Hello - the second displays almost had. what you want to do is joining several tables at once - impossible with the syntax of the oracle, but possible if you use ANSI SQL.

    Wrote file afiedt.buf
    
      1  WITH s AS
      2   (SELECT 1 id, 1 sale_type_id, 10 amount   FROM dual
      3    UNION ALL
      4    SELECT 2, 1, 10  FROM dual
      5    UNION ALL
      6    SELECT 3, 2, 10   FROM dual
      7    UNION ALL
      8    SELECT 4, 2, 10   FROM dual
      9    UNION ALL
     10    SELECT 5, 3, 10    FROM dual
     11    UNION ALL
     12    SELECT 6, 4, 10 FROM dual),
     13  r AS
     14   (SELECT 2 sale_id   FROM dual
     15    UNION ALL
     16    SELECT 3 FROM dual
     17    UNION ALL
     18    SELECT 4 FROM dual),
     19  t AS
     20   (SELECT 1 sale_type_id, 100 sale_type    FROM dual
     21    UNION ALL
     22    SELECT 2, 200    FROM dual
     23    UNION ALL
     24    SELECT 3, 300    FROM dual
     25    UNION ALL
     26    SELECT 4, 400 FROM dual)
     27  SELECT nvl(SUM(s.amount),0) total_amount, t.sale_type
     28    FROM t
     29     join r on (1=1)
     30     left outer join s on (s.id = r.sale_id and s.sale_type_id = t.sale_type_id)
     31   --WHERE s.id(+) = r.sale_id
     32  --   AND s.sale_type_id(+) = t.sale_type_id
     33   GROUP BY t.sale_type
     34*  order by t.sale_type
    SQL> /
    
    TOTAL_AMOUNT  SALE_TYPE
    ------------ ----------
              10        100
              20        200
               0        300
               0        400
    
    4 rows selected.
    

    The two commented lines are what you are trying to achieve using the syntax of the oracle, but which will give you an error.

  • outer join when there are several tables are involved

    Could not put up the question correctly to the last channel, my problem is with the join when there are several tables are involved, this is just one example of the task that I have to carry.

    Tab1 aura model id retailer_id information for all the weeks (from the first Monday) of the month of JUNE with cost and Helen

    Tab1

    model_id

    retailer_id

    sell_date

    cost

    Helene

    1

    12

    June 3, 13

    100

    40

    1

    12

    June 10, 13

    200

    20

    1

    12

    17 June 13

    300

    20

    1

    12

    24 June 13

    400

    20

    2

    12

    June 3, 13

    300

    10

    2

    12

    June 10, 13

    200

    20

    2

    12

    17 June 13

    300

    20

    2

    12

    24 June 13

    400

    20

    Tab2:

    each retailer belongs to a dealer, under the table has the same information

    retailer_id

    Dealer_id

    12

    100

    13

    100

    14

    101

    15

    101

    16

    101

    Tab 3

    There is a third layer where each dealership is having a garage band

    Dealer_id

    Dealer_group

    100

    1001

    101

    1001

    102

    2001

    103

    2001

    104

    3001

    105

    3001

    Tab4:

    Of this table for each model and dealer discount information for the month of June (every week)

    model_id

    Dealer_group

    discount_date

    discount

    1

    1001

    June 3, 13

    10

    1

    1001

    June 10, 13

    20

    1

    1001

    17 June 13

    10

    1

    1001

    24 June 13

    30

    2

    1001

    June 3, 13

    10

    2

    1001

    June 10, 13

    20

    2

    1001

    17 June 13

    10

    2

    1001

    24 June 13

    30

    3

    2001

    June 3, 13

    10

    3

    2001

    June 10, 13

    20

    3

    2001

    17 June 13

    10

    3

    2001

    24 June 13

    30

    Master_info:

    It's the main table which is the master table for model /retailer information

    Model_id

    retailer_id

    1

    12

    2

    12

    3

    12

    4

    12

    1

    13

    2

    13

    Output

    model_id

    retailer_id

    sell_date

    cost

    Helene

    Final (cost-helene-discount)

    1

    12

    June 3, 13

    100

    40

    50

    1

    12

    June 10, 13

    200

    20

    160

    1

    12

    17 June 13

    300

    20

    270

    1

    12

    24 June 13

    400

    20

    350

    2

    12

    June 3, 13

    300

    10

    280

    2

    12

    June 10, 13

    200

    20

    160

    2

    12

    17 June 13

    300

    20

    270

    2

    12

    24 June 13

    400

    20

    350

    3

    12

    June 3, 13

    0

    0

    0

    3

    12

    June 10, 13

    0

    0

    0

    3

    12

    17 June 13

    0

    0

    0

    3

    12

    24 June 13

    0

    0

    0

    4

    12

    June 3, 13

    0

    0

    0

    4

    12

    June 10, 13

    0

    0

    0

    4

    12

    17 June 13

    0

    0

    0

    4

    12

    24 June 13

    0

    0

    0

    1

    13

    June 3, 13

    0

    0

    0

    1

    13

    June 10, 13

    0

    0

    0

    1

    13

    17 June 13

    0

    0

    0

    1

    13

    24 June 13

    0

    0

    0

    2

    13

    June 3, 13

    0

    0

    0

    2

    13

    June 10, 13

    0

    0

    0

    2

    13

    17 June 13

    0

    0

    0

    1

    13

    24 June 13

    0

    0

    0

    For highted above records (model_id / retailer_id combination) there is no record in tab1 but they have entered in master_info then the recordings should come for all model_id/retailer_id with all the 0 values

    Hello

    Thanks for posting the sample data.

    It is unclear what dates you want to include in the output.  The following query shows how you can generate every Monday in a given range.  If you only want to include the dates that are actually present in tabl1 and/or tab4, you can simplify this a bit.

    WITH date_range AS

    (

    SELECT TRUNC (TO_DATE (' 3 June 2013', 'DD-Mon-YYYY'))

    , 'IW '.

    ) AS first_monday

    , TRUNC (TO_DATE (24 June 2013 ', 'DD-Mon-YYYY') + 6)

    , 'IW '.

    ) AS last_monday

    OF the double

    )

    all_mondays AS

    (

    First_monday SELECT + (7 * (LEVEL - 1)) AS sell_date

    OF date_range

    CONNECT BY LEVEL<= 1="" +="" (="" (last_monday="" -="">

    / 7

    )

    )

    SELECT mi.model_id

    mi.retailer_id

    am.sell_date

    , Cost of NVL (t1.cost, 0) AS

    , NVL (t1.rebat, 0) IN the refund

    , NVL (t1.cost, 0)

    -(NVL (t1.rebat, 0))

    + NVL (t4.discount, 0)

    ) AS final

    E master_info

    CROSS JOIN all_mondays am

    LEFT OUTER JOIN tab1 t1 ON t1.model_id = mi.model_id

    AND t1.retailer_id = mi.retailer_id

    AND t1.sell_date = am.sell_date

    LEFT OUTER JOIN tab2 t2 ON t2.retailer_id = mi.retailer_id

    LEFT OUTER JOIN tab 3 t3 ON t3.dealer_id = t2.dealer_id

    LEFT OUTER JOIN tab4 t4 ON t4.model_id = t1.model_id

    AND t4.dealer_group = t3.dealer_group

    AND t4.discount_date = t1.sell_date

    ORDER BY mi.retailer_id

    mi.model_id

    am.sell_date

    ;

    The results are not exactly what said you you wanted.  I suspect it's because of typos in that you posted.

  • Best approach to join several statistical tables in one

    I read different approaches to join several statistical tables in one, they all have a column 'productobjectid '.

    I want to get all the data for each product and put it in excel, then output a jpg cfchart with statistics.

    How would you do that, the part of sql?

    Thank you.

    Your "abiguous" is caused when you reference multiple tables in your SQL query that have the same field name.

    for example

    TableA a field 'ID '.

    TableB also has a field named "ID".

    If your select statement was:

    SELECT *.

    OF inner join TableA TableB on TableA.myField = TableB.myField

    WHERE ID = 4

    then SQL would be panic because he doesn't know which field ID in which table you are trying to access.  Your best bet is always prefix your domain names with the name of your table (or an alias - alias are very useful if you have long table names) when you do a Select statement.

  • Join the execution of several Tables Plan

    Try to understand the query execution plan:
     
    
    HR>  SELECT e.last_name , d.department_name, l.city
      2     FROM employees e, departments d , locations l
      3     WHERE e.department_id = d.department_id
      4   AND
      5           d.location_id = l.location_id;
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1235509609
    
    --------------------------------------------------------------------------------------------------
    | Id  | Operation                     | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT              |                  |   106 |  4346 |     9  (23)| 00:00:01 |
    |*  1 |  HASH JOIN                    |                  |   106 |  4346 |     9  (23)| 00:00:01 |
    |   2 |   MERGE JOIN                  |                  |    27 |   837 |     6  (34)| 00:00:01 |
    |   3 |    TABLE ACCESS BY INDEX ROWID| DEPARTMENTS      |    27 |   513 |     2   (0)| 00:00:01 |
    |   4 |     INDEX FULL SCAN           | DEPT_LOCATION_IX |    27 |       |     1   (0)| 00:00:01 |
    |*  5 |    SORT JOIN                  |                  |    23 |   276 |     4  (50)| 00:00:01 |
    |   6 |     VIEW                      | index$_join$_003 |    23 |   276 |     3  (34)| 00:00:01 |
    |*  7 |      HASH JOIN                |                  |       |       |            |          |
    |   8 |       INDEX FAST FULL SCAN    | LOC_CITY_IX      |    23 |   276 |     1   (0)| 00:00:01 |
    |   9 |       INDEX FAST FULL SCAN    | LOC_ID_PK        |    23 |   276 |     1   (0)| 00:00:01 |
    |  10 |   TABLE ACCESS FULL           | EMPLOYEES        |   107 |  1070 |     3   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------
    So he needs to MERGE between DEPARTMENTS (that has been sorted by index) JOIN and (here's the part confusing...) LOCATIONS including oracle used HASH JOIN (?) to bring the information from and then sort the opinion generated by the system that has been created...?

    Is that this HASH JOIN to step 7 only refers to a view that is generated by the system that oracle had to sort and not actually HASH JOIN
    between two tables?

    Thanks much for you patience

    Hello

    Perhaps, it helps to understand things better if we walk in the plan.

    Plans have a hierarchical structure (which is translated graphically by fingerprints). Operating needs parent all the children completed operations before it can do its job (which is generally combining lines with children in one way or another).

    Another point is that joins can have anything like their entries, tables not only. That is a hash join can join an index for an index or a table to an index, or then to join a table results of hash one another and so on and so forth.

    With this in mind, we can go back on what is happening here step by step:

    The needs of the join by hash (1) (2) and (10) to finish. (10) is a basic operation, since a table scan depends on nothing else, but merge join handset (2) (3) and (5), who both are complex operations (i.e. dependent on one or more children). Specifically, lines (3) from the DEPARTMENTS table using ROWID obtained from a full analysis of the index of DEPT_LOCATION_IX (4), (5) is simply lines join hash (7) and sorted in the order required.

    I hope this helps.

    Best regards
    Nikolai

    Published by: Nikolay Savvinov on January 26, 2012 05:26

  • date max with multiple joins of tables

    Looking for expert advice on the use of max (date) with multiple joins of tables. Several people have tried (and failed) - HELP Please!

    The goal is to retrieve the most current joined line of NBRJOBS_EFFECTIVE_DATE for each unique NBRJOBS_PIDM. There are several lines by PIDM with various EFFECTIVE_DATEs. The following SQL returns about 1/3 of the files and there are also some multiples.

    The keys are PIDM, POSN and suff

    Select NBRJOBS. NBRJOBS.*,
    NBRBJOB. NBRBJOB.*
    of POSNCTL. Inner join of NBRBJOB NBRBJOB POSNCTL. NBRJOBS NBRJOBS on (NBRBJOB. NBRBJOB_PIDM = NBRJOBS. NBRJOBS_PIDM) and (NBRBJOB. NBRBJOB_POSN = NBRJOBS. NBRJOBS_POSN) and (NBRBJOB. NBRBJOB_SUFF = NBRJOBS. NBRJOBS_SUFF)
    where NBRJOBS. NBRJOBS_SUFF <>'LS '.
    and NBRBJOB. NBRBJOB_CONTRACT_TYPE = 'P '.
    and NBRJOBS. NBRJOBS_EFFECTIVE_DATE =
    (select Max (NBRJOBS1. NBRJOBS_EFFECTIVE_DATE) as 'EffectDate '.
    of POSNCTL. NBRJOBS NBRJOBS1
    where NBRJOBS1. NBRJOBS_PIDM = NBRJOBS. NBRJOBS_PIDM
    and NBRJOBS1. NBRJOBS_POSN = NBRJOBS. NBRJOBS_POSN
    and NBRJOBS1. NBRJOBS_SUFF = NBRJOBS. NBRJOBS_SUFF
    and NBRJOBS1. NBRJOBS_SUFF <>'LS '.
    and NBRJOBS1. NBRJOBS_EFFECTIVE_DATE < = to_date('2011/11/15','yy/mm/dd'))
    order of NBRJOBS. NBRJOBS_PIDM

    Welcome to the forum!

    We don't know what you are trying to do.
    You want all of the columns in the rows where NBRJOBS_EFFECTIVE_DATE is the date limit before a given date (November 15, 2011 in this example) for all rows in the result set with this NBRJOBS_PIDM? If so, here is one way:

    with         GOT_R_NUM     as
    (
         select       NBRJOBS.NBRJOBS.*,
                NBRBJOB.NBRBJOB.*     -- You may have to give aliases, so that every column has a unique name
         ,       rank () over ( partition by  NBRJOBS.NBRJOBS_PIDM
                                   order by      NBRJOBS.NBRJOBS_EFFECTIVE_DATE     desc
                          )             as R_NUM
         from          POSNCTL.NBRBJOB NBRBJOB
         inner join      POSNCTL.NBRJOBS NBRJOBS       on    (NBRBJOB.NBRBJOB_PIDM = NBRJOBS.NBRJOBS_PIDM)
                                            and      (NBRBJOB.NBRBJOB_POSN = NBRJOBS.NBRJOBS_POSN)
                                      and      (NBRBJOB.NBRBJOB_SUFF = NBRJOBS.NBRJOBS_SUFF)
         where       NBRJOBS.NBRJOBS_SUFF             != 'LS'       -- Is this what you meant?
         and        NBRBJOB.NBRBJOB_CONTRACT_TYPE   ='P'
         and       NBRJOBS.NBRJOBS_EFFECTIVE_DATE  <= to_date ('2011/11/15', 'yyyy/mm/dd')
    )
    select       *     -- Or list all columns except R_NUM
    from       GOT_R_NUM
    where       R_NUM          = 1
    order by  NBRJOBS_PIDM
    ;
    

    Normally this site does not display the <>inequality operator; He thinks it's some kind of beacon.
    Whenever you post on this site, use the other inequality operator (equivalent), *! = *.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) for all the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    You will get better results faster if you always include this information whenever you have a problem.

  • Removal of several tables with only loop FORALL

    I need to remove the data from several tables with unique FORALL. It seems that FORALL does not support. Please let me know the alternatives to achieve this goal.

    DB version: 11 GR 2

    Write switchis for all instructions, one for each deletion. There is no reason why it should not work.

    Compare:

    PLSQL 101 :

    Here are some things to know about FORALL:

    Each FORALL statement can contain only a single DML statement. If your loop contains two updates and a deletion, then you will need to write three statements FORALL

Maybe you are looking for