SQL - Complex join - Cascading conditions

Hi all,
I've the following two tables - 
MasterData - 
Project_ID
Category
Parent_ID
P1
A
NULL
P2
A
NULL
P3
A
NULL
P4
A
P1
P5
A
P1
P6
E
NULL
P7
A
P2
P8
A
P2
P9
A
P3
P10
D
P6
Project_Totals
Project_ID
Total
P1
500
P2
600
P6
700
P10
800
I need to join these two tables and get projects AND their child projects based on the condition Category = A.
Expected Results - 
Project_ID
Total
P1
500
P2
600
P4
NULL
P5
NULL
P7
NULL
P8
NULL
So the projects from Project_totals have to be first obtained with category 'A' condition and their corresponding child projects have to be fetched from Masterdata. I'm not able to construct the query to get the desired results. Can someone help me?
NLV - MCTS - Blog -
Twitter - In

NLV, 
Is this still an issue?
If so, please read Visakh16's last
response. We need more information.
[Personal Site] [Blog] [Facebook]

Similar Messages

  • Sql complex join statements

    I have been seraching for reference material that show
    an illustration of ER Diagrams and SQL join statements.
    I am usually developing queries from looking at an ER diagram and no other documentation. The books I am finding only have simple easy SQL join examples. I can no find a book that shows difficult join queries or relate join queries with ER diagrams. I am stuck in one case
    where I have a table that relates to two other tables but there is a third table in common with both of them.
    How should this join statement look?
    Sometime I code the join logic correct but the parentheses
    are in the wrong place. Can you help on this one as well?

    NLV, 
    Is this still an issue?
    If so, please read Visakh16's last
    response. We need more information.
    [Personal Site] [Blog] [Facebook]

  • RE: Complex Join

    Hi Experts,
    I have few questions regarding complex joins
    1> First when we import the tables into the Physical layer we will do the FK Joins for the tables according to our requirement then in BMM layer we will create new business model next again why we have to make complex join in BMM layer already there is joins between the tables in physical layer which scenarios we have to make the Complex join if we won't do the complex join what will happens.
    2> Also if we do FK join in the place of complex join in BMM layer what will be the result.
    Thanks in Advance,

    Hi,
    we have two joins in OBIEE one is foreign key join and other one is complex join.Mostly 99% cases we use foreign key join in physical layer.we use complex join in phycical layer mostly in three scenarios.
    1)when there is extended join conditions.
    2)when we join key column of one table to non key column of other table.
    3)when the operator is other than equal to operator.
    In these 3 situations we can use complex join in physical layer.
    Next one is we have already joins in physical layer then what is the need to create complex joins in BMM layer right.
    The answer for this question is whenever user runs a report that will generate logical sql query our OBIEE understands only logical sql query this logical sql query generated based on the logical joins in BMM layer.
    Based on this logical joins only it will create most optimized sql query.And another reasons for creating logical joins is
    if we want to specify driving table it is possible only thriugh complex join in BMM layer.
    and if we want to specify type of join it is possible only thriugh complex join in BMM layer
    and if we want to specify cordinality it is possible only thriugh complex join in BMM layer
    and another one is my tool is not able to identify facts and dimensions because it has no intelligence,we need to incorporate the intelligence by giving logical joins only it identifies the facts and dimensions.
    so we have to create logical joins in BMM Layer..
    Give me Like,,if you aresatisified with my post.
    Thanks,
    Sai Pelluri

  • How to use complex function as condition in Oracle Rule Decision Table?

    How to use complex function as condition in Oracle Rule Decision Table?
    We want to compare an incoming date range with the date defined in the rules. This date comparison is based on the input date in the fact & the date as defined for each rule. Can this be done in a decision table?

    I see a couple of problems here.
    First, what you posted below is not a syntactically valid query. It seems to be part of a larger query, specifically, this looks to be only the GROUP BY clause of a query.
    Prabu ammaiappan wrote:
    Hi,
    I Have a group function in the Query. Below is the Query i have used it,
    GROUP BY S.FREIGHTCLASS,
    R.CONTAINERKEY,
    S.SKU,
    S.DESCR ||S.DESCRIPTION2,
    S.PVTYPE,
    RD.LOTTABLE06,
    R.WAREHOUSEREFERENCE,
    RD.TOLOC,
    R.ADDWHO,
    R.TYPE,
    S.CWFLAG,
    S.STDNETWGT,
    S.ORDERUOM,
    R.ADDDATE,
    C.DESCRIPTION,
    (CASE WHEN P.POKEY LIKE '%PUR%' THEN 'NULL' ELSE to_char(P.PODATE,'dd/mm/yyyy') END),
    NVL((CASE WHEN R.ADDWHO='BOOMI' THEN RDD.SUPPLIERNAME END),SS.COMPANY),
    RDD.BRAND,
    S.NAPA,
    RD.RECEIPTKEY,
    R.SUSR4,
    P.POKEY,
    RDD.SUSR1,
    r.STATUS, DECODE(RDD.SUSR2,' ',0,'',0,RDD.SUSR2),
    rd.SUSR3Second, the answer to your primary question, "How do I add a predicate with with a MAX() function to my where clause?" is that you don't. As you discovered, if you attempt to do so, you'll find it doesn't work. If you stop and think about how SQL is processed, it should make sense to you why the SQL is not valid.
    If you want to apply a filter condition such as:
    trunc(max(RD.DATERECEIVED)) BETWEEN TO_DATE('01/08/2011','DD/MM/YYYY') AND TO_DATE('01/08/2011','DD/MM/YYYY')you should do it in a HAVING clause, not a where clause:
    select ....
      from ....
    where ....
    group by ....
    having max(some_date) between this_date and that_date;Hope that helps,
    -Mark

  • One to one join, complex join

    How can I make a one to one join in physical layer??
    And, when can I use complex join in Physical layer???
    Thanks in advance

    In physical layer it is simple join when you join two objects like fact and dimension. You can change the cardinality of the join in BMM by specifying the relationship(like one-one, one - many and so on)
    In simple join it is always an equal to condition. You will not be able to change the condition b/w joins
    The complex join can be used when you are using like a between, greater than or less than operator joins between two columns. It is not recommended to use a complex join as it impacts performance
    Hope it helps
    Thanks
    Prash

  • Complex Join

    Hi,
    Why we use complex Join in Physical Layer?

    Hey Apart from regular joins, we can write a complex join conditions using experssions.
    http://obinsight.blogspot.com/2010/05/understanding-complex-join-and-physical.html

  • What is the different between Logical complex join and Physical join?

    hi,
    Do somebody know what is the function different between logical complex join in BMM layer and physical join in physical layer?
    Thanks.

    Thank you very much1
    I understand their differentiation:
    In the BMM Complex join (intelligent), means OBI picks the best way from possibly many different ways to join using physical join. FK join forces the same join always, which limits flexibility.

  • Designer - complex join not displayed correctly

    Post Author: Jon80
    CA Forum: General Feedback
    I've created a complex join as part of a tutorial for aggregate aware tables.  So I've created a complex join as follows within the e-fashion universe:
    Calendar_year_lookup.Yr=Agg_yr_qt_mt_mn_wk_rg_cy_sn_sr_qt_ma.Yr and Calendar_year_lookup.Week_In_Year=Agg_yr_qt_mt_mn_wk_rg_cy_sn_sr_qt_ma.Wk
    When selecting Detect, the cardinality detected is many-to-many.  Is it bad practice in this case?  Does it have to be resolved?
    It is noted that when I edit the join (e.g. double click the join), the cardinality that was previously detected is not shown within the Edit Join dialog.  Why?
    Then I try to create a context for this join, however at this stage it is noted that within the formula bar and within the New Context dialog the join is not displayed as it is expected, hence misleading to the designer:
    Calendar_year_lookup.Yr=Calendar_year_lookup.Week_In_Year=Agg_yr_qt_mt_mn_wk_rg_cy_sn_sr_qt_ma.Wk
    It would be helpful if the formula bar and the New Context dialog could accomodate the two lines created.
    As a matter of fact when I do copy and paste the join is pasted, as expected, i.e. how I have updated it previously:
    Calendar_year_lookup.Yr=Agg_yr_qt_mt_mn_wk_rg_cy_sn_sr_qt_ma.Yr and Calendar_year_lookup.Week_In_Year=Agg_yr_qt_mt_mn_wk_rg_cy_sn_sr_qt_ma.Wk
    Reference: Business Objects XI - The Complete Reference 2nd Ed pg.250

    Hello,
    most recent patches for IGS and kernel installed. Now it works.

  • OBIEE 11g - complex join in physical layer

    Hi, I need to create a complex join in the physical layer with join criteria like the following:
    fact.fiscal_year = dim.fiscal_year and fact.accounting_period <= dim.accounting_period
    Every time I try to do this, I get the nQSError: 37005 Transaction Update Failed message. Any ideas what is going on?
    Thanks,
    Scott

    Actually, I (finally) got it to work - wow logical joins are a big pain in the butt in 11g. First off, I had to edit the RPD offline, couldn't get it to work (at all) online.
    Next I had to delete the existing joins...there appears to be no way to change an existing FK join into a logical join.
    Next created the logical joins as stated in my original post - but had to fiddle with it for about 15 minutes to get it to work. You can NOT click the two columns on the dim side, two columns on the fact side, and then just edit the default formula (which defaults to have = sign between the expressions) - because it creates a FK join, and then you start getting errors. Instead, I had to build the expression from scratch.
    All in all, 11g has gotten much less flexible and easy to use in this regard.
    Scott

  • A complex join . Please help

    I have a complex join to perform.
    I need some help please.
    I have a table call Table A
    TableA
    id_entity    inst_type     inst_code  dt_trade
    AGL          SE              5660249    01 Feb '06
    AGL          SE              5660249    01 Feb '06
    AGL          SE              5660249    05 Feb '06
    TableB
    id_inst                 id_inst_xref
    0029010          SE     5660249
    0070789          SE     5660249
    0071190          SE     5660249
    0072385          SE     5660249
    0073215          SE     5660249
    0084797          SE     5660249
    0091375          SE     5660249
    Table C
    id_inst     id_isin
    0029010     FR0000120172
    0070789         FR0000120172
    0071190     FR0000120172
    *** All the id_inst in TableC have the same id_isinAll the 3 Tables now have to be linked to together such that
    Output
    id_entity    Inst_code   id_isin         dt_trade    count
    AGL          5660249     FR0000120172    01 Feb '06  2
    AGL          5660249     FR0000120172    02 Feb '06  1What I am doing is
    Select ta.id_entity,ta.id_inst_code,ta.dt_trade,tc.id_isin,count(*)
    from  TableA ta,TableB tb,TableC tc
    where ta.id_entity = 'AGL'    and
          ta.inst_code       = (How do I get the id_inst from TableB)
                                and then use the id_inst from TableB
                                to get the id_isin from TableC)
    group by ta.id_entity,ta.id_inst_code,ta.dt_trade,tc.id_isin
    Can I say :
    Select ta.id_entity,ta.id_inst_code,ta.dt_trade,tc.id_isin,count(*)
    from  TableA ta,TableB tb,TableC tc
    where ta.id_entity = 'AGL'    and
          ta.inst_code = (Select distinct tb.id_inst
                          from tableB tb
                          where tb.id_inst_xref = ta.id_inst_code
                          ) and then link the id_inst from here to TableC ang get the id_isin??Can someone please help.??

    I had a bit of a go at writing the query but I don't quite understand the data. Here is what I tried.
    jeff@ORA10GR2> create table tablea
    2 (id_entity varchar2(3)
    3 ,inst_type varchar2(3)
    4 ,inst_code number
    5 ,dt_trade date);
    Table created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> insert into tablea values ('AGL', 'SE', 5660249, to_date('20060201','YYYYMMDD'));
    1 row created.
    jeff@ORA10GR2> insert into tablea values ('AGL', 'SE', 5660249, to_date('20060201','YYYYMMDD'));
    1 row created.
    jeff@ORA10GR2> insert into tablea values ('AGL', 'SE', 5660249, to_date('20060205','YYYYMMDD'));
    1 row created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> create table tableb
    2 (id_inst number
    3 ,inst_type varchar2(3)
    4 ,id_inst_xref number);
    Table created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> insert into tableb values (0029010, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0070789, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0071190, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0072385, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0073215, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0084797, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0091375, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> create table tablec
    2 (id_inst number
    3 ,id_isin varchar2(20)
    4 );
    Table created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> insert into tablec values (0029010, 'FR0000120172');
    1 row created.
    jeff@ORA10GR2> insert into tablec values (0070789, 'FR0000120172');
    1 row created.
    jeff@ORA10GR2> insert into tablec values (0071190, 'FR0000120172');
    1 row created.
    jeff@ORA10GR2>
    jeff@ORA10GR2>      select tb.id_inst_xref, tc.id_isin
    2      from tableb tb, tablec tc
    3      where tb.id_inst = tc.id_inst;
    ID_INST_XREF ID_ISIN
    5660249 FR0000120172
    5660249 FR0000120172
    5660249 FR0000120172
    jeff@ORA10GR2>
    jeff@ORA10GR2> select ta.id_entity,ta.inst_code,ta.dt_trade,dt.id_isin,count(*)
    2 from tablea ta,
    3      (select tb.id_inst_xref, tc.id_isin
    4      from tableb tb, tablec tc
    5      where tb.id_inst = tc.id_inst) dt
    6 where ta.inst_code = dt.id_inst_xref
    7 group by ta.id_entity,ta.inst_code,ta.dt_trade,dt.id_isin;
    ID_ INST_CODE DT_TRADE ID_ISIN COUNT(*)
    AGL 5660249 05/FEB/06 FR0000120172 3
    AGL 5660249 01/FEB/06 FR0000120172 6
    jeff@ORA10GR2>
    jeff@ORA10GR2> drop table tablea;
    Table dropped.
    jeff@ORA10GR2> drop table tableb;
    Table dropped.
    jeff@ORA10GR2> drop table tablec;
    Table dropped.
    jeff@ORA10GR2>
    jeff@ORA10GR2> spool off

  • Reg Complex Join

    Hi Experts,
    In which cases we have to use complex join in physical layer i saw in many blogs that we have to implement at the time implementing SCD type -2 in physical layer . May i know one scenario that where we have t exactly use the complex join in physical layer for better under standing.
    In which cases we have to use foreign key join in BMM layer.
    Regards,

    You got it right:
    During SCD II we go for complex join in Physical layer
    ex: sales date is between sales rep's start and end dates-> You may google it for SCD II scenarios
    In this case we go for Logical foreign key join in BMM
    Other than this case we go for complex join (in physical layer) when we dont have valid keys to join, and we go for regular complex join in BMM
    If helps pls mark

  • Complex join and f.k. join

    Hi Team,
    In which cases we will go complex join in physical layer and f.k. join BMM layer.
    thanks,

    In the BMM layer its recommended to use Complex joins always, as in this case obiee will dynamically select
    which Logical table sources to join together from the Logical tables, and put some intelligence in choosing this source. a FK join here would mean that obi has to always use the table sources specified even if it is not the optimum one.
    Complex join is used in the physical layer when there is no direct foreign key - primary key relationship between tables e.g. >,< is required to join instead of =.

  • Complex join goes missing during import

    morning,
    i got a complex join between 2 dimension tables (in physical layer: one table is alias of existing dimension table; other is geo hir table) which goes missing when i try to import the new SA into the existing repository (the join is in the new SA)
    there are 3 other complex joins (remaining geo hir tables that also join on alias table) which theoretically are identical and which dont go missing; i see no difference between any of them
    id appreciate any suggestions what i could check to prevent this from happening
    Edited by: UserMB on Apr 14, 2009 1:57 AM

    yes, i know its not supported
    during import the catalog is select for sure plus the security group
    i tried the merge too (following the instructions for merge with blank rep), but then it creates a second database connection instead of merging into existing one as though it would not recognize that its the same one

  • Extremely Complex Join.

    Hi there
    I posted a thread yesterday about a field I had in a DB that was a varchar and held two different formats for dates e.g closed time varchar(50) , Output ==> 15/12/01 or 12/15/01.
    After a bit more research into this column I found that all rows held in a mmddyy format were from the year 00. Im am now looking to join this column to another table but I am finding it increasingly difficult. As the dates are all mixed up I am unable to do just a simple join so at the moment I am restricting the column on the join to bring back anything after 2000 and I am taking our substrings of the data and then concatenating them together to bring back the desired format.
    However when I run this along with an aggregate I am getting crazy figures e.g sum of all closed jobs within a period. The piece of SQL I am using is too long to post up and is really slow but at the moment I have no other choice. Below is an example of the join I am trying to create. Any suggestions would be really appreciated.
    Dates Table
    Field = Period (varchar) e,g. 012004
    Field = Date(varchar) e.g 20040101
    Feild = Seconds From(number) e.g. 1076544728
    Field = Seconds To(number) e.g. 1076546728
    2nd Table
    Field = Closed Time(varchar) e.g. 15/12/01 16:28:09 or 12/15/01 16:28:09.
    Join = Period to to_char(closed time, MMYYYY)
    or I have tried to convert closed time to seconds which I cant do or convert to a date
    any suggestions?
    Thanks a million

    You appear to have an unnecessary cartesian join to my_table in your subquery. The following may be what you are looking for. This query hits on the PL/SQL rounding issue but produces whole numbers in SQL;
    SQL> create table my_table as (
       select '01/01/00 11:11:11' closed_time from dual union all
       select '01/01/01 11:11:11' from dual union all
       select '01/01/01 11:11:12' from dual union all
       select '01/01/50 11:11:11' from dual)
    Table created.
    SQL> -- Cartesian join to my_table 
    SQL> SELECT   (b.closed_date - TO_DATE ('01-JAN-1970', 'DD-MON-YY'))*24 *60 *60 AS closed_seconds
      FROM (SELECT TO_DATE (a.closed_time, 'dd/mm/yy hh24:mi:ss') AS closed_date
              FROM (SELECT closed_time
                      FROM my_table
                     WHERE SUBSTR (closed_time, 7, 2) > 00
                       AND SUBSTR (closed_time, 7, 2) < 50) a,
                   my_table) b,
           my_table
    WHERE ROWNUM < 1000
    CLOSED_SECONDS
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347470,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    978347471,9999
    32 rows selected.
    SQL> -- Remove cartesian 
    SQL> SELECT (TO_DATE (closed_time, 'dd/mm/yy hh24:mi:ss') -
            TO_DATE ('01-JAN-1970', 'DD-MON-YY')) *86400 closed_seconds
    FROM (   
       SELECT closed_time
       FROM my_table
       WHERE SUBSTR (closed_time, 7, 2) > 00
       AND SUBSTR (closed_time, 7, 2) < 50)
    CLOSED_SECONDS
    978347470,9999
    978347471,9999
    2 rows selected.

  • Sql to JOIN 3 tables

    I need some help on my sql to join 3 tables.
    I am close, but my results come out to be a multiple of what im supposed to get.
    I am trying to retrieve a sum from table 2 and table 3.
    there are 4 records in table2 and 3 records in table3
    the results SHOULD be 3 and 20
    but i get 12/60
    which is a number i shoudl get times the #records of the oppposite table.
    i have moved my code in different arrangements to see if that is the issue, but it doesnt seem to matter.  i still get the result of a multiple.
    Heres my code so far:
    SELECT sum(table3.field) AS sumtable3, sum(table3.field) AS sumtable2
    FROM table1
    LEFT JOIN table2 ON table1.id=table2.id
    LEFT JOIN table3 ON table2.id=table3.id
    GROUP BY table1.id
    ORDER BY table1.id

    Please provide sample data for all 3 tables.

Maybe you are looking for

  • Getting my line upgraded

    Hi After numerous emails I have finally got BT to admit that my BB speed was poor, 1.2meg, I live about 2 miles from the exchange . They have done some  sort of upgrade in the exchange and I am now receiving 3.5meg in the test socket. Ok a good impro

  • Extract R/3 Hierarchies Directly into BW

    I'm going to create a DataSource on R/3 system to extract the R/3 hierarchy into BW. I have read the article concerning this, but the are some unclear moments to me about R/3 hierarchies. What if I just have created General Hierarchy via transaction

  • Crystal Reports and Essbase

    Does anyone have any impressions/experience/opinions/hints about using Crystal Reports 8.5 with Essbase 6+. In specific, does anyone know how to speed up the reports? It is painfully slow on my end.Thanks,Jason Cole

  • Candy crush not connecting to facebook

    Any solution to connect candy crush to Facebook? Seems after last update it stopped connecting.

  • Help needed for photos deleted from Verizon Cloud

    After selecting muliple photos in Verizon Cloud, they were inadvertently deleted rather than downloaded to my PC.  These photos had been deleted from my phone after backed up to Verizon Cloud.  The Trash Can in my Verizon Could has contacts and music