Need to join if it corresponds

Hello

I got out of two different select statement with me and these two different tables.

RAJA > select count (a.dist_id), dist_id of alpha one group by dist_id;

COUNT (A.DIST_ID) DIST_ID

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

1 300

6 100

2 200

4 400

4 selected lines.

RAJA > select sum (venue_cap), dist_id of the alpha1 group by dist_id;

SUM (VENUE_CAP) DIST_ID

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

1 50

2 200

2 selected lines.

my need to join these out by writing a single application. then can someone suggest me a way. Thanks in advance.

Hello

How to get the desired results of your data depends on your data and the results you want.  View the desired results and your data (CREATE TABLE and INSERT for examples of data; instructions lines maybe 5 of each table).

It seems that you have a Siphon of the abyss, i.e. 2 separate 1-to-many relationships where 1 dist_id occur on the number of lines of the alpha and alpha1 tables.  When you need to make the aggregate on both tables, you do aggregates on at least one of the tables, before joining the other.  For example:

WITH alpha_results AS

(

SELECT COUNT (*) AS alpha_count

dist_id

Alpha

GROUP BY dist_id

)

SELECT ar.dist_id

ar.alpha_count

SUM (a1.venue_cap) AS total_venue_cap

From ar alpha_results

LEFT OUTER JOIN alpha1 a1 ON a1.dist_id = ar.dist_id

GROUP BY ar.dist_id

ar.alpha_count

;

Yet once, as long as I don't know where you're going, I can't guarantee that this is going to take you there.

Tags: Database

Similar Questions

  • I bought the plan for photography and still pay each month. but I can't use photoshop only after update. and they need to join a plan. How can I do? I can only use for the trial version even I never tell months.

    I bought the plan for photography 6 months ago and still pay every month.

    but I can't use photoshop only after update. and they need to join a plan.

    How can I do?

    I can only use for the same test version that I pay every month.

    Hi yejik42305752,

    Please see the following article: https://helpx.adobe.com/creative-suite/kb/trial--1-launch.html

    Kind regards

    Tanuj

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

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

    create table tab1 (identification number,

    date of eff_date,

    Code1 varchar2 (2),

    Code2 varchar2 (2)

    )

    /

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    tab1

    ID, date, code 1, code2

    2. DID DAT 2015-01-14

    2. DID DAT 2015-03-19

    2. DID DAT 2015-08-28

    2. DID DAT 2015-11-12

    2 AE DAT 2015-01-03

    2 AE DAT 2015-03-14

    2 AE DAT 2015-04-18

    2 AE DAT 2015-09-14

    2 BS DAT 2015-01-14

    2 BS DAT 2015-02-14

    2 BS DAT 2015-03-14

    BE DAT 2 2015-05-14

    3. DID DAT 2015-09-16

    3 AE DAT 2015-04-16

    What I need to do...

    1 auto join to match EI for each partition ID

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

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

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

    5. the same rules for BS and BE.

    result should look like this.

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

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

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

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

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

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

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

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

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

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

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

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

    Select a.*, b.* from

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

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

    full outer join

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

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

    on a.id = b.id

    and a.rn = b.rn

    and a.eff_date < = b.eff_date

    Hello

    owbdev99 wrote:

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

    create table tab1 (identification number,

    date of eff_date,

    Code1 varchar2 (2),

    Code2 varchar2 (2)

    )

    /

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

    ...

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

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

    WITH got_next_e_date AS

    (

    SELECT id, eff_date, code1, code2

    MIN (CASE

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

    THEN eff_date

    END

    ) OVER (PARTITION BY ID.

    , SUBSTR (code2, 1, 1)

    ORDER BY eff_date DESC

    ) AS next_e_date

    OF tab1

    )

    s AS

    (

    SELECT *.

    OF got_next_e_date

    "WHERE SUBSTR (code2, 2) s ="

    )

    e

    (

    SELECT *.

    OF got_next_e_date

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

    )

    SELECT s.id

    s.eff_date

    s.code1

    s.code2

    e.id AS id_1

    e.eff_date AS eff_date_1

    e.code1 AS code1_1

    e.code2 AS code2_1

    S

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

    AND s.next_e_date = e.eff_date

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

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

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

    , SUBSTR (e.code2, 1, 1)

    )

    s.eff_date

    ;

    Out (as you asked):

    ID EFF_DATE CODE1, CODE2 ID_1 EFF_DATE_1 CODE1_1 CODE2_1

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

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

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

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

    2. DID DAT 2015-11-12

    2 AE DAT 2015-01-03

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

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

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

    3. DID DAT 2015-09-16

    3 AE DAT 2015-04-16

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

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

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

  • need help joins

    I'm not real upward on the rules of ansi joins... I could use some help.

    I have a question where I do a full outer join, but I need to do an outer join as well. This syntax is incorrect. How can I get it correct?

    Of
    bae_bom_std_oprtns_syn bso,
    bae_mtl_parameters_syn mp,
    (select * from bae_quality_nonconform_mv)
    where nc_date_creat between 1st April 08 ' and 30 April 08') bnc
    FULL OUTER JOIN
    (select * from bae_quality_sfw_job_mv)
    where last_updt between 1st April 08 ' and 30 April 08') j
    ON j.job_oper_seq = bnc.job_oper_seq
    where
    j.operation_code = bso.operation_code (+)
    and mp.organization_id = bso.organization_id

    the (+) sign throws a syntax error, but how do I do that if I want to get data based on this left join?

    Thanks for the help...

    Hello

    Whenever you post the code on this site, type the 6 characters
    {code}
    (small letters only, inside curly braces) before and after the formatted text, to maintain spacing.
    Good helps you catch many errors of formatting, including imbalanced or misplace between parentheses.

    You do several other things that are not strictly errors, but ask for trouble:
    (a) mix ANSI and non-ANSI joins
    b implicit string to DATE conversions
    (c) 2chiffres years

    I think that's what you want to do:

    FROM         (     SELECT  *
                   FROM     bae_quality_nonconform_mv
                        WHERE     nc_date_creat     BETWEEN TO_DATE ('01-APR-2008', 'DD-MON-YYYY')
                                       AND     TO_DATE ('30-APR-2008', 'DD-MON-YYYY')
              ) bnc
    FULL OUTER JOIN (     SELECT  *
                           FROM     bae_quality_sfw_job_mv
                   WHERE     last_updt     BETWEEN TO_DATE ('01-APR-2008', 'DD-MON-YYYY')
                                  AND     TO_DATE ('30-APR-2008', 'DD-MON-YYYY')
              ) j                    ON  j.job_oper_seq      = bnc.job_oper_seq
    LEFT OUTER JOIN     bae_bom_std_oprtns_syn     bso  ON  j.operation_code    = bso.operation_code
    LEFT OUTER JOIN     bae_mtl_parameters_syn     mp   ON  mp.organization_id  = bso.organization_id 
    
  • Need help joining 2 prels in a movie

    Hi I want to raise two PE9 prels film, how can I do this?

    Kind regards... Andy

    When I create intermediate files, which will be published later, I use a CODEC lossless, as Lagarith or UT Lossless. This article goes into details: http://forums.adobe.com/thread/875797?tstart=0

    For extended accounts of YouTube, we'll have to share a YouTube compatible file (see this FAQ entry: http://forums.adobe.com/thread/623549?tstart=0 ) and then manually download them via your extended account. Even when pre 10 has been encoded, there is no extended YouTube accounts, sort of pre is wired into the former limitation of duration.

    I guess that PrE 11 will have the capacity of extended account, but then YouTube will propose a Super account long, and we'll have at hand and manually download, brand-new.

    Good luck

    Hunt

  • Need to know the grain of the join table

    Hi Experts,

    I have a doubt,

    Let say I take data from two tables
    pay_costs
    PAY_COST_ALLOCATIONS_F

    for tables, the columns are
    pay_costs. BALANCE_OR_COSTS
    pay_costs. DEBIT_OR_CREDIT

    PAY_COST_ALLOCATIONS_F.PROPORTION

    Now, I need to join these two tables respectively. I followed site etrm and found that we can create the join

    PAY_COST_ALLOCATIONS_F.PAY_COST_ALLOCATION_KEYFLEX = PAY_COST_ALLOCATION_KEYFLEX. PAY_COST_ALLOCATION_KEYFLEX
    and PAY_COST_ALLOCATION_KEYFLEX. COST_ALLOCATION_KEYFLEX_ID = pay_costs. COST_ALLOCATION_KEYFLEX_ID

    so I'm doing something wrong. The grain of the data is going to change... Help kindly I am new to the field of ebs

    Hello
    You will potentially have millions of records in PAY_COSTS because it's the main compensation table.

    Your PAY_COST_ALLOCATIONS_F contains only a breakdown of how the costs of a user should be broken out. There is an ASSIGNMENT_ID (which connects to the person) and a PROPORTION corresponding to the percentage.

    Depending on how long the person has been with the company, for each assignment ID (that you can consider PERSON_ID), there might be hundreds of files in PAY_COSTS.

    The primary key of the PAY_COSTS is the COST_ID while the primary key of the PAY_COST_ALLOCATIONS_F is COST_ALLOCATION_ID more EFFECTIVE BEGIN and EFFECTIVE END dates. Which tells me, is that the benefits are time and if you try and join the ALLOCATION_ID you will end up with a wrong answer. If you were within the E-Business Suite, application effective date using the current date as the default value. Then, it does is apply a filter on all tables that have dates of application. Thus, for example, you may have to limit benefits to know those that this could be done using this SQL:

    SELECT
    ASSIGNMENT_ID, COST_ALLOCATION_KEYFLEX_ID, PROPORTION
    Of
    HR. PAY_COST_ALLOCATIONS_F
    WHERE
    SYSDATE BETWEEN EFFECTIVE_START_DATE AND EFFECTIVE_END_DATE
    ORDER OF ASSIGNMENT_ID, COST_ALLOCATION_KEYFLEX_ID

    You can get a clue by COUNT (*) from the two tables. If there are more records from a table that another so you can be sure that there is not a join one of 1:1 and therefore the granularity must be 1: n one-to-many

    Hope this helps
    Michael

  • Table DB need join help

    I'm trying to follow some RTF data to a language specification... I have installation test record this follow-up. I am able to find in spec summary test specifications and the specific information I'm looking for in the HTMLData table. What I can't find is the join track to return to the wording PKID of HTMLData. Can I get help with the PL - SQL Query?

    The data schema says EP HTMLdata doesn't have all the relationships, but there is a PKID PLM4P referenced in the FKPARENT column, which starts by "2220" which takes me to the richtextsupportingdocuments table. Schema docs say that this table has no relationship either. However richtextsupportingdocuments table has a FKspec column that refers to an object beginning with '5818' and that takes me to gsmFormulationSteps. gsmFormulationSteps titles back to FormulationInput that does not have a formula PKID/FKID of '5618' but rather '1004' for materials, etc... so that's where I'm stuck... I am moving back to the spec formualution ID and not been followed correctly of the 5816 PKID.

    Could someone help me get back on track with the data track? Thank you.

    Good question - the configuration of database for formulating specifications is a little different from other specifications (since you can have snapshots of a language specification). So it is not that simple. You need to join DWBSpecificationRoots and fkWorkingVersionParent of dwbSpecifications column, as below

    SELECT ss. SpecID, ss. SpecNumber, as follows. StepName, html. HtmlContent
    OF specsummary ss
    INNER JOIN DWBSpecificationRoots t2 ON ss.specid = t2.fkOwner
    INNER JOIN t3 ON t2.pkid = t3.fkWorkingVersionParent dwbSpecifications
    Steps to INNER JOIN gsmFormulationSteps t3.pkid = steps.fkParent
    inner join richTextSupportingDoc on richText.fkSpec = steps.pkid richText
    HtmlData html on html.fkParent = richText.pkid inner join
    where
    SS. SpecID =

  • Need help with the condition join in SQL

    Hi all -

    I need to ask for help with this query:

    Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));

    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ("Column3", 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('column4', 'table1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ("column1", "table2", 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column2', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', "Column3", 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table2', 'column4', 'varchar2')
    Commit;

    Create table all_cons_columns_test (varchar2 (30) from table_name, column_name varchar2 (30), constraint_name varchar2 (30))

    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "primary")
    Insert into all_cons_columns_test (table_name, column_name, constraint_name) values ("table1", "column1", "secondary")
    Commit;

    This is my query and the current result:

    Select u.table_name, u.column_name, c.constraint_name
    Of user_tab_col_test u
    Outer join all_cons_columns_test c left
    On (u.table_name = c.table_name
    AND U.COLUMN_NAME = C.COLUMN_NAME
    AND C.CONSTRAINT_NAME IN ('main'))
    order of U.table_name, U.COLUMN_NAME;

    TABLE_NAME COLUMN_NAME, CONSTRAINT_NAME
    ------------------ --------------------- ----------------------------
    Table1 primary Column1
    Table1 Column2
    Table 1 Column3
    Table2 Column1
    Table2 Column2


    Three questions:
    (1) I don't want to return results where table_name = "table1". I can't get this to work.
    (2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.
    (3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?

    Any advice/suggestions are appreciated-
    John

    Published by: user703358 on January 11, 2013 20:57

    Published by: user703358 on January 11, 2013 21:48

    Hi, John,.

    user703358 wrote:
    Hi all -

    I need to ask for help with this query:

    Create table user_tab_col_test (varchar2 (30) from table_name, column_name varchar2 (30), data_type varchar2 (30));

    Insert into user_tab_col_test (table_name, column_name, data_type) values ('table1', 'column1', 'varchar2')
    Insert into user_tab_col_test (table_name, column_name, data_type) values ('Column2', 'table1', 'varchar2')...

    Thanks for posting the CREATE TABLE and INSERT.
    It is more useful if you post the code that can be run without modification. You did not semicolons after INSERTION instructions.

    Three questions:
    (1) I don't want to return results where table_name = "table1". I can't get this to work.

    What have you tried? Post your best attempt.
    Here's one way:

    SELECT    u.table_name
    ,        u.column_name
    ,        c.constraint_name
    FROM             user_tab_col_test      u
    LEFT OUTER JOIN  all_cons_columns_test  c
                            ON    u.table_name     = c.table_name
                   AND   u.column_name     = c.column_name
                   AND   c.constraint_name IN ('primary')
    WHERE       u.table_name     = 'table1'          --  *****  NEW  *****
    ORDER BY  u.table_name
    ,            u.column_name
    ;
    

    You would not put this condition in the clause; who controls what is considered as a match between the tables, and "u LEFT OUTER JOIN c" means show all lines of u, even if they do not have a match in the c.

    (2) is my proper request and this is the best way to return my desired results? For example, I want all of the columns of user_tab_col_test and I want to only display the constraint_name from all_cons_columns_test argument if the argument constraint_name = 'primary '.

    Basically, this application is very well.
    It displays all the columns of user_tab_col_test; missing data_type. Just add u.data_type to the SELECT clause, or change the SELECT clause

    SELECT    u.*
    ,         c.constraint_name
    

    (3) will be the synatx be the same if I need to join a third table to all_cons_columns_test?

    Do you mean "" * add * one-third * column * to all_cons_columns_test '? "
    It depends on what results you want. Post new CREATE TABLE and INSERT and instructions the results you want new data.
    Most likely, the basic structure of what you've written will remain exactly the same.

  • Join on 1 row help need

    In a database associated with bad, I need to join A table with table B, where the relationship (apply, no keys) is usually from 1:1, but can be 1:many in some cases. If it is 1:many, I need only return a record (as if it were 1:1) and ignore the rest. Returned check of table B is not serious, but the fields must all be of the same folder. Is there a way to do this?
    Here is an example of what I'm trying to do:

    ID name
    ======
    1 franc
    Joe 2
    3 Ralph

    ID phone Type AddedDate Notes
    ==============
    12/12/2009 1 the work 555-1234 A note
    1 House of the 222-4321 14/11/2009 something
    2 House of 434-4343-20/12/2009
    3 House 333-3433, 10/30/2009
    select * from People A, PhoneNums B
    where A.id = B.id
    I would like to receive back ONLY 3 elements, one for each record in the table has. For table B, no matter if the join on ID 1 returns the work or home in the join, I just need one of them. If I try something like this...
    select * from People A, (select Id, Max(Phone), Max(Type), Max(Notes) From PhoneNums group by Id) B
    where A.id = B.id
    ... Can I get a recording, but the fields might not be the same record, since when I group by Id, Max (Phone) might not be on the same line as Max (Type) etc.

    Any suggestions?

    One way:

    select *
    from people a,
         (select id, phone, type, notes
          from (select id, phone, type, notes,
                       row_number() over(partition by id
                                         order by null) rn
                from phonenums)
          where rn = 1) b
    where a.id = b.id
    

    John

  • Problem with the implementation of Outer JOIN

    Hello Guru,

    Here's my scenario. I know that this can be achieved in several ways. But I need this in a single in aid Of JOINS EXTERNALrequest.

    I have two tables namely masters and transactions table. I need to join two columns (trx_name, trx_type) of the two tables and the need for all transactions. Part the trickiest is off 2 join columns, one column can be NULL in the main table.

    Script TABLES:

    create master table (mstr_no number, trx_name varchar2 (100), trx_type varchar2 (100), trx_module varchar2 (100));

    insert into masters values (1, 'yyyy', 'simple', 'cont');
    insert into masters values (2, 'bbbb', < NULL >, "cust");
    insert into masters values (3, 'yyyy', 'triple', "cont1");

    create table transaction (trx_no number, trx_name varchar2 (100), trx_type varchar2 (100));

    Insert in transaction values (1, 'yyyy', 'simple');
    Insert the transaction values (2, 'bbbb', 'double');
    Insert in transaction values (3, 'yyyy', 'triple');
    Insert in transaction values (4, 'cccc', 'purple');
    commit;

    I need output like below.

    1, 'yyyy', 'simple', 'cont '.
    2, 'bbbb', < NULL >, * "cust."
    3, 'yyyy', 'triple', "cont1".
    4, 'cccc', 'purple', < NULL >

    I need to join trx_name & trx_type in the two tables. Even if one of the column is null in the main table (mstr_no = 2), I have need of the corresponding value of trx_module since trx_name made match.


    My query:
    Select a.*, b.trx_module of transaction a, master b
    where a.trx_name = b.trx_name (+)
    and a.trx_type = NVL (b.trx_type (+), 'NULL')
    order of a.trx_no

    Appreciate your help.


    Concerning
    MN

    Maybe I'm wrong, but I don't think you can do this with a single outer join:

    with
    full_matches as (
    select *
      from master
     where trx_type is not null)
    ,
    partial_matches as (
    select *
      from master
     where trx_type is null)
    select a.*
         , coalesce(b.trx_module, c.trx_module) trx_module
      from transaction a
      left outer join full_matches b
        on (a.trx_name = b.trx_name and a.trx_type = b.trx_type)
      left outer join partial_matches c
        on (a.trx_name = c.trx_name)
     ;
    
    TRX_NO TRX_NAME             TRX_TYPE             TRX_MODULE
    ------ -------------------- -------------------- ------------
         1 aaaa                 single               cont
         3 aaaa                 triple               cont1
         2 bbbb                 double               cust
         4 cccc                 purple
    

    Re-reading my answer, I see that a short explanation might be useful: the query uses two outer joins: first masters lines with the name and type are joined, and then type the lines with missing. Him coalesce work to choose the most relevant information of module.

    Published by: Martin Preiss on June 7, 2013 20:24

  • Outer join with Oracle syntax

    Hi, I am new to oracle and I worked this request for reports for about 2 weeks, please take a look at my request
    SELECT mmt.transaction_date "Transaction Date", 
                msib.segment1 "Item", 
                gcc.segment1||'-'||gcc.segment2||'-'||gcc.segment3||'-'||gcc.segment4||'-'||gcc.segment5||'-'||gcc.segment6||'-'||(nvl(gcc.segment7,'000000')) "account",
                (CASE mttype.transaction_type_name
                WHEN 'Average cost update' THEN
              ((nvl(mmt.new_cost,0) - nvl(mmt.prior_cost,0)) * nvl(mmt.quantity_adjusted,0)) + nvl(mmt.variance_amount,0)
                ELSE
                 (mmt.Primary_quantity * nvl(mmt.actual_cost, 0) + nvl(mmt.variance_amount, 0))
               END) "Transaction Value",
                mttype.description "Transaction Type",
                mmt.subinventory_code "Subinventory",
                ood.organization_code "Org",
                msib.Primary_UOM_Code "UOM",
                mmt.Primary_Quantity "Primary Quantity",
                mtr.description "Reason",
                mmt.transaction_reference "Reference"
    FROM mtl_material_transactions mmt,
             mtl_system_items_b msib,
             mtl_transaction_accounts mta,
             gl_code_combinations gcc,
             mtl_transaction_types mttype,
             Org_Organization_Definitions ood,
             mtl_transaction_reasons mtr
    WHERE mmt.transaction_date >= :P_DATE_FROM 
               and mmt.transaction_date  < :P_DATE_TO +1
               and mmt.organization_id = :P_ORGANIZATION 
               and msib.organization_ID = mmt.organization_ID  
               and msib.inventory_item_id=mmt.inventory_item_id 
               and mta.transaction_id=mmt.transaction_id
               and gcc.code_combination_id = mta.reference_account
               and mttype.transaction_type_id=mmt.transaction_type_id
               and mmt.reason_id=mtr.reason_id(+)
               and ood.organization_id=mmt.organization_id
               and mttype.transaction_type_id = :P_TRANSACTION_TYPE
               and msib.segment1 = :P_ITEM
               AND gcc.segment2 = :P_ACCOUNT
    null values is on the mtl_material_transactions table, which is reason_id, subinventory_code and transaction_reference
    put desired option on would show all archives on mtl_material_transactions with null values
    so I put the symbol of the outer join right?
    BTW
    I tried to put the (+) sign on various locations but it still not good and I am really at a loss

    Hello

    Whenever you have any questions, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and the desired results from these data. I know that's not always easy, but it is really necessary. Compounds that, I do not understand your problem.
    It could be useful that simplify you the problem. If you were not interested in, say, the mta, gcc, tables msib and ood, would you still have the same problem? If so, forget all these tables and just after, CREATE TABLE and INSERT statements for the remaining tables and the results you want from this data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

    The query you posted will not exclude any line of mmt just because it doesn't have a corresponding line in the mtr; That's what the condition:

    and mmt.reason_id=mtr.reason_id(+)
    

    but it will exclude mmt lines if they do not have matching rows in other tables. Maybe you need + plus join and may under certain conditions non-join, such as conditions

    gcc.segment2 (+) = :P_ACCOUNT
    

    Too much. It's just a guess. Without seeing your sample data and the correct results, you should get from this data, I can't say.

  • How the auto join a jabber chat room

    Does anyone know how auto join a jabber chat room when the account becomes available, I have not found the way, and whenever I go online I have to join the chat room.

    9.1 messages

    Thank you very much

    Hello

    If the cat is left in the main message window as an item in the side bar and of course the cat showing the app needs to 'join' as it is open.

    He may have limits however if the cat needs a password and that you had to sign out when leaving at the end of the previous session.

    As to automatically join such a room I don't think it's possible.

    20:44 Thursday. February 18, 2016

     iMac 2.5 Ghz i5 2011 (Mavericks) 10.9
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro (Snow Leopard 10.6.8) 2 GB
     Mac OS X (10.6.8).
     a few iPhones and an iPad

  • Join the nearest date "not used".

    I need to join the following tables by the next date "not previously signed" the nearest:

    start_table:

    st_id start_dt
    start031-dec-2014
    Start1

    January 3, 2015

    Start2January 5, 2015
    start3January 7, 2015
    Debut48 January 2015
    Debut5January 14, 2015

    end_table:

    end_id end_dt
    end0January 1, 2015
    End1January 2, 2015
    End2January 13, 2015
    End3January 15, 2015
    bout4January 17, 2015
    end519 January 2015
    end6January 20, 2015

    Result:

    st_id end_id
    start0end0
    Start1End2
    Start2End3
    start3bout4
    Debut4end5
    Debut5end6

    start0 joined end0, because the closer to the date of the next 31-dec-2014 is 1 January 2015

    Start1 joined end2, because the closer to the date of the next January 3, 2015 is January 13, 2015.

    Start2 joined end3, because as well as the date of the next more close January 5, 2015 is 13 January 2015, this is already accompanied Start1, so she joined next January 15, 2015.

    start3 joined bout4, because the date of the next although most close January 7, 2015 is 13 January 2015, this one is already joined by Start1, earliest date is January 15, 2015, but is also already joined by start2, then he joined the next available date January 17, 2015.

    Database: 11g

    Thanks in advance

    [UPDATE: changed line 37 to add "or cnt > = 0".] [This covers cases where there are more departures that ends at first.]

    Jiri.Machotka - Oracle wrote:

    I found a non recursive algorithm for this problem...

    I came up with something similar: no recursion, no joins, each table read only once.

    1. UNION ALL marked times 1 tables, with lines of departure and end marked lines - 1
    2. Order by date (first lines) and get a combination of 1's and - 1's.
      so when there are too many lines to end, the sum is negative.
    3. Get the previous cumulative minimum! Then take that end with a sum running lines, at less than the previous minimum.
    4. The remaining lines will have an end of line for each line of departure. Now number lines starting from 1 to N and the lines at the end of 1 to N, then match lines start and end in pairs. I use PIVOT to do this.
    WITH end_table (end_id, end_dt) AS (
      select 'end0',to_date('01-jan-2015','dd-mon-yyyy') from dual union all
      select 'end1',to_date('02-jan-2015','dd-mon-yyyy') from dual union all
      select 'end2',to_date('13-jan-2015','dd-mon-yyyy') from dual union all
      SELECT 'end3',to_date('15-jan-2015','dd-mon-yyyy') FROM dual UNION ALL
      select 'end4',to_date('17-jan-2015','dd-mon-yyyy') from dual union all
      SELECT 'end5',to_date('19-jan-2015','dd-mon-yyyy') FROM dual UNION ALL
      SELECT 'end6',to_date('20-jan-2015','dd-mon-yyyy') FROM dual
    )
    ,start_table (start_id, start_dt) AS (
      select 'start0',to_date('31-dec-2014','dd-mon-yyyy') from dual union all
      select 'start1',to_date('03-jan-2015','dd-mon-yyyy') from dual union all
      select 'start2',to_date('05-jan-2015','dd-mon-yyyy') from dual union all
      select 'start3',to_date('07-jan-2015','dd-mon-yyyy') from dual union all
      select 'start4',to_date('08-jan-2015','dd-mon-yyyy') from dual union all
      SELECT 'start5',to_date('14-jan-2015','dd-mon-yyyy') FROM dual
    )
    , start_and_end as (
      select -1 rowtype, end_id id, end_dt dt from end_table
      union all
      select 1, s.* from start_table s
    )
    , running_count as (
      select se.*,
        sum(rowtype) over(order by dt, rowtype desc) cnt
      from start_and_end se
    )
    , filtered_ends as (
      select rowtype, id, dt from (
        select rc.*,
          min(decode(rowtype,-1,cnt)) over(
            order by dt, rowtype desc
            rows between unbounded preceding and 1 preceding
          ) mincnt
        from running_count rc
      )
      where cnt >= nvl(mincnt,0) or cnt >= 0
    )
    select * from (
      select rowtype, id,
      row_number() over(partition by rowtype order by dt) rn
      from filtered_ends
    )
    pivot(max(id) for rowtype in(1 st_id, -1 end_id))
    order by rn;
    

    ST_ID END_ID RN

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

    1 start0 end0

    2 Start1 end2

    3 Start2 end3

    4 start3 bout4

    5 debut4 end5

    Debut5 6 end6

  • Admin BI - FK does new join unnecessary?

    I create a new model of physics using the BI administration tool. In some cases, when I try to create a new join between two tables via the physical schema, I see that both tables are already bound by an arrow, which means a foreign key. This means that a new join is not necessary?

    Hello

    The data modeling depends entirely on what is your requirement. If you plan to use the same physical table columns in the user interface you don't need to join another physical since it will be redundant.

    However, if you are not sure on the model of data in use and you want to create one yourself and then create aliases for tables in the physical layer and move forward with the definition of your knuckles.

    I hope this helps.

    Mark the correct answer if that answers your query.

    Kind regards

    Arko

  • Need help on request

    Hello


    Could someone help me please on this query:


    drop table tt1;

    create the table tt1 (id number);

    Insert into tt1 values (1);

    Insert into tt1 values (2);

    Insert into tt1 values (3);

    Insert into tt1 values (7);

    Insert into tt1 values (8);


    drop table tt2;

    create table tt2 (identification number, name varchar2 (30));

    insert into tt2 values (7, 'Name 7');

    insert into tt2 values (8, 'Name 8');

    insert into tt2 values (11, ' 11 name ');

    insert into tt2 values (12, 'Name 12');

    commit;


    Select * from tt1;

    ID

    ----------

    1

    2

    3

    7

    8

    Select * from tt2;

    NAMES OF ID

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

    7 name 7

    8 name 8

    Name 11 11

    Name 12 12

    The result of the query should be:

    NAMES OF ID

    1

    2

    3

    7 name 7

    8 name 8

    Thanks in advance!

    Hello

    If you want each line of tt1 joined in its corresponding row in tt2, but if there is no corresponding row in tt2, you want to show data from tt1 anyway; Isn't it?

    That's exactly what outer joins have been designed to do:

    SELECT tt1.id

    tt2.names

    OF tt1

    LEFT OUTER JOIN tt2 ON tt1.id = tt2.id

    ORDER BY tt1.id

    ;

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

Maybe you are looking for

  • Mac OS installers Sierra

    I participated in the incremental updates of Sierra. I have trouble downloading one of my computers. I am told that if I saved an installer which I must first remove before making the final download. Where can I find this Setup program if I have regi

  • May not know how to check the updates of Firefox for Ubuntu

    I'm under "Firefox 3.6.13 Mozilla Firefox for canonical Ubunto - 1.0". How can I verify updates? Here the user manual in the help site says to look for updates in the Help menu article, but there is no such a. I can't find it in the Tools menu or Edi

  • Equium A210 - need drivers for Windows XP

    Hello world I have a Toshiba Satellite A210 (details below). It came with Vista, and I would like the downgrade to XP. I looked around a bit and it seems to be not a lot of info on downgrade from Vista to XP, but not for this specific machine. I also

  • I would like to know is made for Sansa Fuze, allowing me to control it via headphones?

    Let me clarify the subject. I like the way the player is locked by dragging down the power switch. But put it on my Pocket then get a song I don't want to hear right now and need to unlock before locking back is a bit frustrating. So I would like to

  • How to make shortcut to an item on the net?

    I would like to make a shortcut (icon on my screen) to a program that I can access on the net.  Procedure?