Several joins

Hi all

Am new to OBIEE and I need help on the scenario below.

I have two tables S_ORG_EXT (Account) and S_OPTY (Opportunity).

Account table has a direct 1:M join table opportunity. S_ORG_EXT ROW_ID = S_OPTY. Account_ID

But opportunity table also stores data on competitors in his Competior_ID column, which is nothing else than the ROW_ID of account. Even like this, there Partner information in the Partner_ID column.

The requirement set out in the report is now to display the names of account and competing in a single table view.

I created several joins between tables account and opportunity in the physical layer of the repository as follows:

S_ORG_EXT. ROW_ID = S_OPTY. Account_ID
S_ORG_EXT. ROW_ID = S_OPTY.Competitor_ID
S_ORG_EXT. ROW_ID = S_OPTY. Partner_ID

This approach is correct? Can you have multiple joins between two tables?

How can I achieve my requirement of report.

Please help me.

Thanks in advance,
Imtiaz.

@imitiaz

got your requirment, I had an idea is to make a table alias of the table and join with chart of accounts... the second join you mentioned above create this join with her and pull out of this column to your view. Hope this workzz

Tags: Business Intelligence

Similar Questions

  • Several joins between records

    Hi gurus,

    I have a fact table that contains several fields of candidate that can be attached to a lookup table

    2 folders
    fact_table
    lookup_table1

    2 joins are possible between two folders
    fact_table.code_combination_id-> lookup_table1.code_combination_id
    fact_table.accrual_code_combination_id-> lookup_table1.code_combination_id

    When I try to create a new workbook and include the fields of the fact table, and then include the fields of the table of correspondence he asks me to choose the join.

    If I then want to add fields based on the second join, it do not ask me what join to use in the future. He seems to assume that the first join is always between two records for the report. I know that I can create another folder using the same table and move one of the existing joints of the current folder to the new folder. Am I missing something or is this the only way to go?

    Kind regards

    John

    Hi John,.

    Interesting question. This is how we solved in my last job.

    Created files:

    Fact table: AR's

    Search folder: combination of Code search
    Search folder: search for combination of Code of accumulation

    Then join AR made in each search folder. Generally, point the search folder on the AR folder in creating joins. Discoverer, prefer this direction. As a combination of additional code types are referenced, add additional code combination files. All of these files come from the same table. The only thing that is different is the column joined actually AR.

    So, in the end, your knuckles would be:
    Code combination Lookup.code_combination_id-> AR Fact.code_combination_id
    Accrual Code combination Lookup.code_combination_id-> AR Fact.accrual_code_combination_id

    I hope this helps.

    Kind regards
    Nancy

  • Need help with the update with several joins statement

    I have the following select statement, which takes 29 records:
    SELECT
    PAA. PROJECT,
    PAA. SEGMENT1,
    PEIA.expenditure_item_id,
    PEIA.expenditure_type,
    PEC.expenditure_comment
    OF PA.PA_PROJECTS_ALL APP.
    PEIA PA.pa_expenditure_items_all,
    PEC PA.pa_expenditure_comments
    where PPA.segment1 < '2008' and
    PPA.project_id = 52 and - just run for project # 20077119 for the test
    PEIA.expenditure_type = 'PAY' and
    PEIA.project_id = ppa.project_id and
    PEC. EXPENDITURE_ITEM_ID = PEIA. EXPENDITURE_ITEM_ID;

    I need to update the pec.expenditure_comments to a static field for 29 records. I guess I should start with the following, but don't know how to fill in the where:
    Update
    PEC PA.pa_expenditure_comments
    Set pec.expenditure_comment = ' REFERENCE HD #728'.
    where
    ???

    First time we have ever needed to update, so any help appreciated.

    Try using are:

    update pa.pa_expenditure_comments pec
    set    pec.expenditure_comment = 'REFERENCE HD#728'
    where exists ( select null
                   from   pa.pa_projects_all ppa
                   ,      pa.pa_expenditure_items_all peia
                   ,      pa.pa_expenditure_comments pec2
                   where  ppa.segment1 < ''    -- not sure what you posted here, so for next time:
                                               -- please put your examples between the code tags.
                   and    ppa.project_id = 52  -- just run for project # 20077119 for testing
                   and    peia.expenditure_type = 'PAYROLL'
                   and    peia.project_id = ppa.project_id
                   and    pec2.expenditure_item_id = peia.expenditure_item_id
                   and    pec2.expenditure_item_id = pec.expenditure_item_id
                 );
    
  • Need help for query joining views

    Hi all

    I need to run a query that joins a number of tables with multiple instances of the same view.  For example, a view named MY_VALUES, is an array of key / value resembles the following:

    Application_ID Attirbute_Description value

    1 1 000 basic benefit

    1 multiplier 1 0.5

    1 Multiplier_2 1.2

    1 total profit 1,115

    2 1 025 basic benefit

    2 multiplier 1 0,268

    2 Multiplier_2 1.3

    Total profit 2 1.4500

    Say I want a query that selects basic earnings and a multiplier 1 for Application ID 1, as well as, other information from a table called APPLICATION that has a relationship to display pk - fk. I would do the following:

    Select the application. Name, mv1.value, mv2.value

    from dbo. App APPLICATION, dbo. MY_VALUES mv1, dbo. Mv2 MY_VALUES

    where app.id = mv1.application_id and mv1.attribute_description = "Basic benefits"

    and app.id = mv2.application and mv2.attribute_description = id 'multiplier 1'.

    and app.id = 1

    My actual query is similar to this. However, I have many other attributes of the notice I need to select, which requires that the view be attached to several times. After 16 these joins, the request is fine. After 17, however, the query runs always, never return a result within 45 minutes I have let it run.

    Is there a better way to write such a request or an indicator of optimization that would be useful here?

    Any help is greatly appreciated.

    ....

    For this type of application, it is often best to extract multiple lines in a single request on the view and their pivot in the output.

    For example

    Select the application. Name

    , max (CASE when mv.attribute_description = "Core service" then mv.value any other purpose) BaseBenefit

    , max (CASE when mv.attribute_description = 'Multiplier 1' then mv.value any other purpose) Multiplier1

    , max (CASE when mv.attribute_description = 'Multiplier 2' then mv.value any other purpose) Multiplier2

    , max (CASE when mv.attribute_description = 'Multiplier 3' then mv.value end to another null) Multiplier3

    from dbo. App APPLICATION, dbo. MY_VALUES mv

    where app.id = mv1.application_id

    and mv.attribute_description IN ('benefits of home', 'multiplier 'multiplier 'multiplier 3' 2' 1')

    and app.id = 1

    This runs often much better than several joins to the table for the view or the value of the attribute.

  • Need help in the optimization of the query with the Group and joins by clause

    I'm having the problem by running the following query... It takes a lot of time. To simplify, I added the two tables FILE_STATUS = stores the file load details and COMM table Board table job showing records treated successfully and which was communicated to the other system real. Records with status = T is trasnmitted to another system and traansactions with P is waiting.
    CREATE TABLE FILE_STATUS
    (FILE_ID VARCHAR2(14),
    FILE_NAME VARCHAR2(20),
    CARR_CD VARCHAR2(5),
    TOT_REC NUMBER,
    TOT_SUCC NUMBER);
    
    CREATE TABLE COMM
    (SRC_FILE_ID VARCHAR2(14),
    REC_ID NUMBER,
    STATUS CHAR(1));
    
    INSERT INTO FILE_STATUS VALUES ('12345678', 'CM_LIBM.TXT', 'LIBM', 5, 4);
    INSERT INTO FILE_STATUS VALUES ('12345679', 'CM_HIPNT.TXT', 'HIPNT', 4, 0);
    
    INSERT INTO COMM VALUES ('12345678', 1, 'T');
    INSERT INTO COMM VALUES ('12345678', 3, 'T');
    INSERT INTO COMM VALUES ('12345678', 4, 'P');
    INSERT INTO COMM VALUES ('12345678', 5, 'P');
    COMMIT;
    Here's the query I wrote to give me the details of the file that has been loaded into the system. He reads the table of State and the commission files to display the name of the file, total records loaded, total at the table of the commission and the number of records which has finally been passed successfully loaded (Status = T) with other systems.
    SELECT 
        FS.CARR_CD 
        ,FS.FILE_NAME 
        ,FS.FILE_ID
        ,FS.TOT_REC
        ,FS.TOT_SUCC
        ,NVL(C.TOT_TRANS, 0) TOT_TRANS
    FROM FILE_STATUS FS
    LEFT JOIN
    (
        SELECT SRC_FILE_ID, COUNT(*) TOT_TRANS
        FROM COMM
        WHERE STATUS = 'T'
        GROUP BY SRC_FILE_ID
    ) C ON C.SRC_FILE_ID = FS.FILE_ID
    WHERE FILE_ID = '12345678';
    In production, this request has several joins and takes a long time to deal with... the main culprit for me is the join on the COMM table to count the number of number of transactions sent. Please can you give me tips to optimize this query to get results faster? What I need to delete the Group and use the partition or something else. Help, please!

    Don't know if it will be faster based on the information provided, but analytical functions offer an alternative approach;

    select carr_cd, file_name, file_id, tot_rec, tot_succ, tot_trans
      from (select fs.carr_cd,
                   fs.file_name,
                   fs.file_id,
                   fs.tot_rec,
                   fs.tot_succ,
                   count(case
                            when c.status = 'T' then
                             1
                            else
                             null
                          end) over(partition by c.src_file_id) tot_trans,
                   row_number() over(partition by c.src_file_id order by null) rn
              from file_status fs
              left join comm c
                on c.src_file_id = fs.file_id
             where file_id = '12345678')
     where rn = 1;
    
    CARR_CD FILE_NAME            FILE_ID           TOT_REC   TOT_SUCC  TOT_TRANS
    ------- -------------------- -------------- ---------- ---------- ----------
    LIBM    CM_LIBM.TXT          12345678                5          4          2
    
  • Using the RPD Union queries

    Hello

    I need in which I table based on active groups, that is, each group is to have a separate table.

    Now my reports queries all active groups. How to design in the RPD.

    * We are unable to build the union of all reports.

    Let's take an example

    A group table

    Group key

    Column1

    Column2

    Group B table

    Group key

    Column1

    Group C table

    Group key

    Column2

    Column1 and column2 here's respective information, but for groups of various assets (is there, we have 3 tables)

    The tables of dimensions.

    Tried to make paintings like LTS for a single logical table. But the query consists of a single table with two columns

    Thanks in advance

    Rémy Agarwal

    1 table of logic with several (NOT an LTS with several joined tables) LTSS valued content of their respective fragmentation.

    Update: and don't forget to put "this source must be combined with other sources at this level" = TRUE

  • Select the last record

    In the following query, I want only one record for Robert (later) and a record for all peoples in R1. Tried several joins, but do not know why it does not work

    drop table r1;

    create table r1

    (

    index_id NUMBER,

    first name VARCHAR2 (10),

    created DATE by DEFAULT SYSDATE

    );

    Insert into r1 (index_id, name) VALUES (1, 'Joe');

    Insert into r1 (index_id, name) VALUES (2, 'Robert');

    Insert into r1 (index_id, name) VALUES (3, 'John');

    commit;

    drop table r2;

    create table r2

    (

    index_id NUMBER,

    Field1 VARCHAR2 (10),

    VARCHAR2 (10) Field2.

    created DATE by DEFAULT SYSDATE

    );

    Insert into r2 (index_id, Field1, Field2) VALUES (2, "REC1", "OLD");

    Insert into r2 (index_id, Field1, Field2, created) VALUES (2, 'REC1', 'NEW', sysdate + 1);

    commit;

    Select r1.*, r2.* from r1, r2,

    (

    Select f.index_id as ind, f.field1, max (f.created) as last

    R2 f

    F.index_id, f.field1) abc

    where r1.index_id = r2.index_id

    and r2.created = abc.latest

    and r2.index_id = abc.ind (+);

    .

    Like this?

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

    SELECT *.

    SINCE r1,.

    (SELECT f.index_id AS ind, f.field1, MAX (f.created) AS last

    R2 f

    F.index_id, f.field1) r2

    WHERE r1.index_id = r2.ind (+);

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

    INDEX_ID FIRST NAME CREATED IND FIELD1 LATEST
    2 Robert 04/07/2013-06:43 2 REC1 05/07/2013-06:43
    3 John 04/07/2013-06:43
    1 Joe 04/07/2013-06:43

    If not then please post your results

    See you soon,.

    Manik.

  • How the importance of the "advice" in a SQL query when optimizing the query?

    I'm tuning an application (Documentum) and the query contains advice. See the request below for example... a very simple example to show the point; actual queries are one more page of time with several joins.

    During approval of the application (possibly adding new indexes), how is it important to grant the request WITH ADVICE, or can I get advice from the setting process? It's the FORCE_ORDER indicator.

    Select / * + SORTED * / object_name dm_sysobject_s;

    Welcome to the forum!

    Whenever you post, provide your Oracle 4-digit.
    >
    I'm tuning an application (Documentum) and the query contains advice. See the request below for example... a very simple example to show the point; actual queries are one more page of time with several joins.

    During approval of the application (possibly adding new indexes), how is it important to grant the request WITH ADVICE, or can I get advice from the setting process? It's the FORCE_ORDER indicator.

    Select / * + SORTED * / object_name dm_sysobject_s;
    >
    The overall goal is to have NO clues in the production code.

    Advice would normally be to help determine why Oracle has not chosen the best plan for the work to do. Once you know which plan is best seeks the Oracle to use this plan without the need to add a hint to do.

    Tips are sometimes necessary (e.g. the DRIVING_SITE hint) and for batch processes that operate on independent tables (intermediate tables) APPEND it hint is used oftne.

    Who put the tip in the Documentum query? If she was not part of your own people to be careful if you decide to remove it.

    When you have a query that is already at work that has a hint of make you that get the current execution plan before you make changes to the query. You will need this plan after that any withdrawal "tuning" or suspicion that do you to make sure that the plan has not changed.

  • Standardization

    What is the difference between standard and of standard dimensions? That you can recommend in obiee?

    Hello

    As opposed to denormalization, the purpose of the standardization process is to reduce redundancy (same information stored more than once) and ensure the integrity of the data (the database contains valid information).
    This is achieved by reducing the large entities (large, which means a large number of attributes) into several other, lesser entities that set contains the same information, but not repeat it.

    There are methods such as 1NF, 2NF... to normalize the data...
    Contains standardized... tables summary of data...
    And denormalized tables contains data at the level of detail...

    A tables dénormalisée can divided in n normalized number tables depends on your condition... at the level of the database...

    Due to normalization, we find more tables that involves several joins and leads to have less performance...
    Normalization tables are very easy to maintain and easy to build diagrams in Star...
    With standard tables, we will have other than the star schema... (snowflake)...

    2. that you can recommend in obiee?

    A. Standardization-(Star always good schema for obiee).

    Hope this helps

    Thank you
    Satya

  • Cannot display some reports in Discoverer Viewer

    Hi all

    The administrator account can see all of the statements. However, users cannot access some reports.

    1. all reports were shared by users
    2. users have access to the business districts
    3 traps fan is disabled
    4 users have following privileges:
    a. collect query statistics
    b. article drill
    c. ream
    d. Appendix specifications
    e. create the link

    The error message is the following:


    Could not open the requested worksheet:
    -Oracle BI discoverer is unable to find the requested worksheet.
    -BIB-10310 an unknown exception occurred.
    -Join configuration cannot be resolved. Reason: more than 1 records detail use elements not aggregated. Try to open the workbook failed.

    Thank you
    Put

    Hello
    Ask users who attempt to open workbooks to do the following:

    1. access the discoverer Plus
    2. from the menu bar, go to tools | Options
    3. on the Advanced tab, check the box to protect the trap disable fan
    4. Save options
    5. try to open the workbook again

    If it is not resolved, you will also need to allow the user to use several joins. This option is also available on the same tab, but first try the trap of the fan.

    Best wishes
    Michael

  • Interactive report that returns 0 rows on the initial screen of forcing

    How can I get the initial display of my interactive to have 0 rows (and quickly) reports on the initial display, so that the user can determine the lines they want without having to wait for the report view without much in the way of the filters?

    My reports many lines of 50-100 k with several joins of tables: so they are slow and the initial default result set is not useful for them, until they start of construction interactive filters themselves.

    I tried to add a default I / filter R which is never true, return 0 rows, but if I have good corrrectly, APEX will execute the sql 1, returning the default #of ranks backward, THEN that wraps like a subselect and applies to the i / R filters. So, I still have to wait for the report of 'run' before its filtered to 0 rows...

    I'm experimenting also with a flag of pxx_firsttime, intiall value, and according to my report SQL NVL(:Pxx_FIRSTTIME,'Y') = n and (rest of joins of tables)...
    the problem I have with this is, how can I get this option the value N as the user begins to use the interactive report filters, etc., which seem NOT to resubmit the page?

    Thank you

    Hello

    I tried to add a default I / filter R which is never true, return 0 rows, but if I have good corrrectly, APEX will execute the sql 1, returning back by default #of lines, THEN that wraps like a subselect and applies the > I / R filters. So, I still have to wait for the report of 'run' before its filtered to 0 rows...

    Yes, you are right.

    I assume that you already have using the paging Type as line from X to Y.

    the problem I have with this is, how can I get this option the value N as the user begins to use the interactive report filters, etc., which seem NOT to resubmit the page?

    Whenever the user do something with 'Actions', APEX IR will get updated. Thus, to create a dynamic Action that will be triggered before the refreshment of your IR, update the session state from P1_FIRSTTIME_FLAG to "n".

    Kind regards
    Hari

  • Is it possible to chain requests?

    I'm working on an application that needs to work like an ASP.NET web page. To filter the data that I need down to final applications, this time, I have 3 questions that get me the necessary applications. Is there a way in PL/SQL to package the first three queries, so they can be run in the order then enter the result in a view (don't have capabilities of creating table, thinking I'll have to talk to the admin on this.) who access my 2 final queries. The first three queries executed out of each use of the other and I create views for them when I do that on the fly in sqldeveloper. The last two actually return the data that the user wants to see, and what was supposed to appear on the Web page. I've read tutorials and books of PL/SQL and feel just as confused as when I started, so trying to get a small boost in the right direction, then understand it on my own.

    Thanks in advance,

    If I was not clear enough, may include copies of requests, etc. (the first, at the present time, work with three tables and create a view that accesses the following query, and so on).

    Tony

    Hello

    trdunsworth wrote:
    I have 4 settings in the first query and several joins and conditions in which the clause. It would make a difference?

    No, it doesn't matter.

    This is the first query for example:
    create or replace view 'WWPD_STEP1' of force AS
    Select a.eid, a.num_1, e.cdts, e.cpers, a.curent, a.tycod, a.ag_id, beat a.lev3, case when a.priority < '2'="" then="" 'high'="" when="" a.priority=""> ' 2' and 'low', 'normal' else end up as group_priority, substr (e.cdts, 5, 2) | » /'|| substr (e.CDTS, 7, 2) | » /'|| substr (e.CDTS, 1, 4) as disp_date, substr (e.cdts, 9, 6) as let, e.curent AS curent_16, a.ad_sec, a.ds_sec, a.ar_sec, u.csec, a.ds_sec - a.ad_sec as hold_sec, u.csec - a.ds_sec as drive_sec, u.csec - a.ad_sec, resp_sec, a.priority, u.unid
    join to un_hi u (aeven an e event on a.eid = e.eid join) we u.eid = a.eid
    where e.cdts between *: sdate * and *: fdate * and a.tycod in ('' ANIMAL '', 'BUSINESS', "CARCHECK", 'CARSTAT', "CIVSERV", "CKLIGHTS", "COURT", "RACE", 'FOLLOW', 'FOOTPURS', 'GREATMAL', 'HOUSE', 'INFO', 'K9', 'PEDCHECK', 'PRISONER', 'THOMAS', 'SELF', 'SPÉCIAL', 'STATION', 'PHONE', 'TRAFFIC', "TRASH", "WARRANT", "WEATHER")
    and you.unit_status = 'AR '.
    and a.ag_id = *: Agency * and a.ar_sec is not null
    and a.ds_sec is not null
    and a.ds_sec - a.ad_sec between 1 and 7200
    and a.ar_sec - a.ds_sec between 1 and 18000
    and a.ar_sec - a.ad_sec between 1 and 18000
    and you.csec - > 1 a.ds_sec
    and you.csec - a.ad_sec > 2
    order of e.cpers, a.eid, u.csec;

    It works as long as I don't have to invoke the 4th parameter. If I do, I have to use this one instead.
    create or replace view 'WWPD_STEP1' of force AS
    Select a.eid, a.num_1, e.cdts, e.cpers, a.curent, a.tycod, a.ag_id, beat a.lev3, case when a.priority < '2'="" then="" 'high'="" when="" a.priority=""> ' 2' and 'low', 'normal' else end up as group_priority, substr (e.cdts, 5, 2) | » /'|| substr (e.CDTS, 7, 2) | » /'|| substr (e.CDTS, 1, 4) as disp_date, substr (e.cdts, 9, 6) as let, e.curent AS curent_16, a.ad_sec, a.ds_sec, a.ar_sec, u.csec, a.ds_sec - a.ad_sec as hold_sec, u.csec - a.ds_sec as drive_sec, u.csec - a.ad_sec, resp_sec, a.priority, u.unid
    join to un_hi u (aeven an e event on a.eid = e.eid join) we u.eid = a.eid
    where e.cdts between *: sdate * and *: fdate *.
    and in a.tycod ('' ANIMAL '', 'BUSINESS', "CARCHECK", 'CARSTAT', "CIVSERV", "CKLIGHTS", "COURT", "RACE", 'FOLLOW', 'FOOTPURS', 'GREATMAL', 'HOUSE', 'INFO', 'K9', 'PEDCHECK', 'PRISONER', 'THOMAS', 'SELF', 'SPÉCIAL', 'STATION', 'PHONE', 'TRAFFIC', "TRASH", "WARRANT", "WEATHER")
    and you.unit_status = 'AR '.
    and a.ag_id = *: mission *.
    and a.lev3 = *: district *.
    and a.ar_sec is not null
    and a.ds_sec is not null
    and a.ds_sec - a.ad_sec between 1 and 7200
    and a.ar_sec - a.ds_sec between 1 and 18000
    and a.ar_sec - a.ad_sec between 1 and 18000
    and you.csec - > 1 a.ds_sec
    and you.csec - a.ad_sec > 2


    order of e.cpers, a.eid, u.csec;

    It would make a difference?

    N ° if you don't need the 4th parameter, draft the first version. If you don't need the 4th parameter, then use the second version.

    Are you trying to decide at runtime if you use a version or another? If so, you'll either need some kind of mechanism of connection in your front end, otherwise you will need dynamic SQL , where your query is built at run time according to the results of a code, like another query. This can be complex and prone to error.

    Depending on your needs, you might be able to code something in a static query.
    For example, if you want to include the condition

    and a.lev3 = :district
    

    only when: the district is not NULL, then you can do something like this:

    and (    a.lev3     = :district
        OR   :district  IS NULL
        )
    
  • request to combine the view and another query. help please

    I created a view of an important application with several joins.
    view is called
    RM_REPORT

    Im trying to combine this query...
    Select ips_number, tnps1, tnps2, tnps3, TBEFB tnps3. EFBT_TNPS@EFB_ETPSCHP7
    point of view...
    the hook between the two are

    in the view tgeprop and ips_number in the query on the other will need eachother =.


    I can just make...
    SELECT * FROM
    (select * from RM_REPORT) A,
    (select ips_number, tnps1, tnps2, tnps3, TBEFB tnps3. B EFBT_TNPS@EFB_ETPSCHP7)
    WHERE A.TGEPROP = B.IPS_NUMBER
    SELECT A.*,B.* FROM
    RM_REPORT A,
    (select ips_number,tnps1,tnps2,tnps3,tnps3 from TBEFB.EFBT_TNPS@EFB_ETPSCHP7)B
    WHERE A.TGEPROP=B.IPS_NUMBER
    
  • Group by and save County simplification, try #2

    I know what I'm trying to do, don't know how to get there. I provided do it table and inserts as well as the query is not working.
    /*table*/
    CREATE TABLE claims_step_table (  
    table_id       INTEGER PRIMARY KEY, 
    record_id      NUMBER,  
    step_code      VARCHAR2(20 Byte),
    date_completed DATE,
    step_date      DATE
    )
    
    /*inserts*/
    INSERT INTO claims_step_table VALUES (1,  123456,'P96','10-JAN-09','05-JAN-09');
    INSERT INTO claims_step_table VALUES (2,  123456,'L61',null,'05-JAN-09');
    INSERT INTO claims_step_table VALUES (3,  67,'P96','10-MAR-08','05-MAR-08');
    INSERT INTO claims_step_table VALUES (4,  67,'L61',null,'05-MAR-08');
    INSERT INTO claims_step_table VALUES (5,  67,'U18',null,'05-MAR-08');
    INSERT INTO claims_step_table VALUES (6,  67,'429',null,'05-MAR-08');
    INSERT INTO claims_step_table VALUES (7,  9876,'L61',null,'05-FEB-08');
    INSERT INTO claims_step_table VALUES (8,  9876,'429',null,'05-FEB-08');
    INSERT INTO claims_step_table VALUES (9,  123456,'P96','10-AUG-07','05-JUN-07');
    INSERT INTO claims_step_table VALUES (10, 123456,'L61',null,'05-JUN-07');
    INSERT INTO claims_step_table VALUES (11, 123456,'U18',null,'05-JUN-07');
    INSERT INTO claims_step_table VALUES (12, 123456,'429',null,'05-JUN-07');
    INSERT INTO claims_step_table VALUES (13, 67555,'L61',null,'07-NOV-08');
    INSERT INTO claims_step_table VALUES (14, 67555,'P96','08-NOV-08','07-NOV-08');
    INSERT INTO claims_step_table VALUES (15, 67555,'429','15-NOV-08','07-NOV-08');
    COMMIT;
    
    /*query*/
    SELECT
        RECORD_ID,
        max(STEP_DATE)
        from(
                select 
                RECORD_ID,
                STEP_DATE,
                case
                    when STEP_CODE = 'L61' then DATE_COMPLETED
                end as STEP_L61,
                case
                    when STEP_CODE = 'P96' then DATE_COMPLETED
                end as STEP_P96,
                case
                    when STEP_CODE = 'U18' then DATE_COMPLETED
                end as STEP_U18,
                case
                    when STEP_CODE = '429' then DATE_COMPLETED
                end as STEP_429
            from
            CLAIMS_STEP_TABLE
            where
                STEP_CODE in('L61','P96','U18','429')
        )
    where
        STEP_L61 is null
    and
        STEP_P96 is not null
    and
        STEP_U18 is null
    and
        STEP_429 is null
    
    group by RECORD_ID, STEP_DATE
    order by RECORD_ID, STEP_DATE DESC
    What I need is all RECORD_ID and STEP_DATE where
    • STEP_CODE L61, U18 and 429 the null value AND STEP_CODE P96 is over
    • Only the more recent recordings based on the STEP_DATE (so the step_date max), if of multiple RECORD_ID.


    The query should return * 2 * n - tuples
    RECORD_ID       MAX(STEP_DATE)
    67             03/05/2008
    123456             01/05/2009
    I am currently getting the following
    RECORD_ID       MAX(STEP_DATE)
    67             03/05/2008
    67555             11/07/2008 <= step 429 not null
    123456             01/05/2009
    123456              06/05/2007 <= old record need newest
    It is a much more simplified than the original query as it has several joins of tables. There are 100 records of k + in the real CLAIMS_STEP_TABLE with more than 1 different k STEP_CODE. (it is a fictitious table for this example). BTW on the real DB, I have only read access.

    Thank you for your patience and understanding with a noob, hope this attempt is more clear.

    The reason why it is failing because your pivot (inner query) is return few results:

     RECORD_ID STEP_DATE STEP_L61  STEP_P96  STEP_U18  STEP_429
    ---------- --------- --------- --------- --------- ---------
        123456 05-JAN-09           10-JAN-09
        123456 05-JAN-09
            67 05-MAR-08           10-MAR-08
            67 05-MAR-08
            67 05-MAR-08
            67 05-MAR-08
          9876 05-FEB-08
          9876 05-FEB-08
        123456 05-JUN-07           10-AUG-07
        123456 05-JUN-07
        123456 05-JUN-07
        123456 05-JUN-07
         67555 07-NOV-08
         67555 07-NOV-08           08-NOV-08
         67555 07-NOV-08                               15-NOV-08
    

    So in the case of 67555, there is a situation where all the outer query conditions are met. What you need to do is to remove the extra NULL values as follows:

    SELECT  RECORD_ID
    ,       STEP_DATE
    ,       MAX(CASE
                    WHEN STEP_CODE = 'L61' THEN DATE_COMPLETED
            END) AS STEP_L61,
            MAX(CASE
                    WHEN STEP_CODE = 'P96' THEN DATE_COMPLETED
            END) AS STEP_P96,
            MAX(CASE
                    WHEN STEP_CODE = 'U18' THEN DATE_COMPLETED
            END) AS STEP_U18,
            MAX(CASE
                    WHEN STEP_CODE = '429' THEN DATE_COMPLETED
            END) AS STEP_429
    FROM    CLAIMS_STEP_TABLE
    WHERE   STEP_CODE IN ('L61','P96','U18','429')
    GROUP BY RECORD_ID
    ,       STEP_DATE
    

    To achieve this result:

     RECORD_ID STEP_DATE STEP_L61  STEP_P96  STEP_U18  STEP_429
    ---------- --------- --------- --------- --------- ---------
         67555 07-NOV-08           08-NOV-08           15-NOV-08
          9876 05-FEB-08
        123456 05-JUN-07           10-AUG-07
            67 05-MAR-08           10-MAR-08
        123456 05-JAN-09           10-JAN-09
    

    Then your entire query returns the following:

    SQL> SELECT  RECORD_ID
      2  ,       MAX(STEP_DATE)
      3  FROM
      4  (
      5          SELECT  RECORD_ID
      6          ,       STEP_DATE
      7          ,       MAX(CASE
      8                          WHEN STEP_CODE = 'L61' THEN DATE_COMPLETED
      9                  END) AS STEP_L61,
     10                  MAX(CASE
     11                          WHEN STEP_CODE = 'P96' THEN DATE_COMPLETED
     12                  END) AS STEP_P96,
     13                  MAX(CASE
     14                          WHEN STEP_CODE = 'U18' THEN DATE_COMPLETED
     15                  END) AS STEP_U18,
     16                  MAX(CASE
     17                          WHEN STEP_CODE = '429' THEN DATE_COMPLETED
     18                  END) AS STEP_429
     19          FROM    CLAIMS_STEP_TABLE
     20          WHERE   STEP_CODE IN ('L61','P96','U18','429')
     21          GROUP BY RECORD_ID
     22          ,       STEP_DATE
     23  )
     24  WHERE   STEP_L61 IS NULL
     25  AND     STEP_P96 IS NOT NULL
     26  AND     STEP_U18 IS NULL
     27  AND     STEP_429 IS NULL
     28  GROUP BY RECORD_ID
     29  /
    
     RECORD_ID MAX(STEP_
    ---------- ---------
        123456 05-JAN-09
            67 05-MAR-08
    
    SQL>
    

    HTH!

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

Maybe you are looking for