Join of two tables without Cartesian?

--------------------------------------------------------------------------------------------------------
SELECT BAGLANTIDATE, CABONE
FROM SEDEF_BILGI
WHERE CABONE = '1' AND
BAGLANTIDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
--------------------------------------------------------------------------------------------------------
BAGLANTIDATE                CABONE
------------------------- ---------- 
10-JUN-09 03.01.52.546000000 AM 1          
10-JUN-09 05.02.06.453000000 PM 1          
10-JUN-09 01.01.20.421000000 PM 1          
10-JUN-09 07.01.42.062000000 AM 1          
10-JUN-09 09.44.59.515000000 AM 1          
10-JUN-09 09.58.07.843000000 AM 1          
10-JUN-09 09.01.50.546000000 PM 1          

7 rows selected
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
SELECT KAYITDATE, ABONE
FROM GPRS_TB_SAYACISEMRI
WHERE ABONE = '1' AND
KAYITDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
------------------------------------------------------------------------------------------------------------
KAYITDATE                   ABONE
------------------------------------- -------------------
10-JUN-09 09.52.57.796000000 AM 1
10-JUN-09 02.13.32.343000000 PM 1

2 rows selected
I need a code that will help me to show the 9 values in the following form
BAGLANTITARIH        ABONE
------------------------      ----------------
10-JUN-09 03.01.52.546000000 AM 1          
10-JUN-09 05.02.06.453000000 PM 1          
10-JUN-09 01.01.20.421000000 PM 1          
10-JUN-09 07.01.42.062000000 AM 1          
10-JUN-09 09.44.59.515000000 AM 1          
10-JUN-09 09.58.07.843000000 AM 1          
10-JUN-09 09.01.50.546000000 PM 1    
10-JUN-09 09.52.57.796000000 AM 1
10-JUN-09 02.13.32.343000000 PM 1

9 rows
How can I do? If someone helped me on this subject, I would really appreciate it...
Kind regards
Sedef
SELECT BAGLANTIDATE BAGLANTIDATE, CABONE CABONE
FROM SEDEF_BILGI
WHERE CABONE = '1' AND
BAGLANTIDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
union all
SELECT KAYITDATE, ABONE
FROM GPRS_TB_SAYACISEMRI
WHERE ABONE = '1' AND
KAYITDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
AND TO_DATE('11-JUN-2009','DD-MON-YYYY')

Ravi Kumar

Tags: Database

Similar Questions

  • Join of two tables in two different schemas

    Hi all

    I have an obligation to join two tables on two different schemas. How to join these two tables in the object view.

    Thanks in advance.

    Concerning
    Kaushik Guillaumin

    You can do just that using schema name in the +' view object.table name ' + according to the query object and also grant select the another schema to this schema user

    ex
    you need schem is test and another Act you need to a view object based on the test to join a table on shcema Act

    you write semply object sql view code:

    Act.table name

    and you can also give him select statement on Bill schem table to test

    concerning

  • problem with join of two tables

    Hi, consider the following data
    WITH data AS
    (
      SELECT 123 cid, 'aaa' isi, 'kkk' sud, 'ttt' ri FROM dual UNION ALL 
      SELECT 222 cid, 'bbb' isi, 'gggg' sud, 'hhh' ri FROM dual
    
    ) ,
    data2 AS 
    (
      SELECT 'aaa' isi, 'yyy' sud, 'ooo' ri FROM dual UNION ALL 
      SELECT 'qqq' isi, 'ggg' sud, 'ooo' ri FROM dual UNION ALL 
      SELECT 'uuu' isi, 'ppp' sud, 'ttt' ri FROM dual UNION ALL
       SELECT 'ppp' isi, 'mmm' sud, 'nnn' ri FROM dual 
    
    
    )
    what I want to do, is to join data2 with data by isi, ri or southern id table and produce this output.
     cid  txt
     ===  ====
     123  aaa
     222  ggg
     123  ttt
    It's how I got the above output:
    first try to join isi in database2 with isi in "features" and discover if line matches. If this is the case, display the cid of the data table and the use of the value to match.
    e.g. in the first line of table data2, we can see that isi = aaa matches line an isi data table. If the output displays 123 and value aaa.

    If the rank table two of the Data2 isi = qqq. When join them with the data table, we find not all isi with qqq. in this case, it must join with column of South. We can see that South = ggg data2 games
    the second line in the table of output so will bee 222 and value ggg.

    now, take a look at the third row in Database2. ISI = uuu is not found in the data table when join them. then try to join to the South. South = ttt is also not found in any row of the data table. so join with ri. We
    can see that ri = ttt data2 matches with ri = ttt in the table of data online 1. Therefore, we display the value.

    can someone help me write a sql query that joins these two tables by isi. If no line found then join South, if no found rows then join in ri? Thank you

    Hello

    elmasduro wrote:
    Hi Frank, data2.sud = 'Gay' (4 characters) assume to be South = "ggg". by mistake, I type extra g.

    I have another question about the request. What happens if I want to bring rows of data.2 even if they do not exist in the data table for the entire column was join?
    for example, I want to show this:

    cid  txt
    ===  ====
    123  aaa
    222  ggg
    123  ttt
    ppp  --row from data2
    

    the columns of the last row of data.2 does not match any column in the data table. in this case, I want to make but cid will be null. I tried outer join on your request, but it looks like I can not clause or with outer join

    SELECT     d1.cid
    ,     CASE
              WHEN  d1.isi = d2.isi  THEN  d2.isi
              WHEN  d1.sud = d2.sud  THEN  d2.sud
                                            ELSE  d2.ri
         END     AS txt
    FROM data     d1
    JOIN     data2     d2  ON     d1.is(+)i     = d2.isi
                  OR     d1.sud(+)     = d2.sud
                  OR     d1.ri(+)     = d2.ri
    ;
    

    How can I re - write the query for this case? Thanks again for your help

    Here is the outer join syntax:

    SELECT     d1.cid
    ,     CASE
              WHEN  d1.isi = d2.isi  THEN  d2.isi
              WHEN  d1.sud = d2.sud  THEN  d2.sud
              WHEN  d1.ri  = d2.ri   THEN  d2.ri
                                            ELSE  d2.isi
         END     AS txt
    FROM          data2     d2
    LEFT OUTER JOIN     data     d1  ON     d1.isi     = d2.isi
                           OR     d1.sud     = d2.sud
                           OR     d1.ri     = d2.ri
    ;
    

    The + sign for outer joins only works with the old join syntax, non-ANSI. Do not try to mix the two different ways to do joins.

    Not to mention that the outer join, don't forget to change the CASE expression, to include the new possibility of any columns 3 join matching.

  • Extraction of data from two tables without discounting

    Hi friends,

    I have a problem I want to extract data from two tables without discount in the text field when I will enter any value in a text field, then the value of corressponding must come to textfield corressponding.

    for example. There are two table A and B.
    Table A has Colunm

    S_ID number;
    C_ID Varchar2 (30);
    VARCHAR2 (4) s;

    Second table B Colunm name

    S_ID number;
    What varchar (30);
    L_Name varchar (20);

    When I enter in a text field then the c_id 101 s_id, dry, first_name and last_name should come to corressponding text without refresh fields.

    How can I do that.

    Thank you
    Maury

    You can use Ajax and there are tons of good examples out there for this purpose;
    For example [http://apex.oracle.com/pls/otn/f?p=31517:236:1876567353842241]

  • How it warns Oracle to use an index for the join of two tables...

    How to prevent the Oracle to use an index for the join of two tables to get a view online that is used in an update statement?

    O.K. I think I should explain what I mean:

    When you join two tables that have many entries sometimes there're better is not to use an index on the column that is used as a criterion to join.

    I have two tables: table A and table B.

    Table A has 4,000,000 entries and table B has 700,000 entries.

    I have a join of two tables with a numeric column as join criteria.

    There is an index on this column in A table.

    So I instead of
      where (A.col = B.col)
    I want to use
      where (A.col+0 = B.col)
    in order to avoid Oracle using the index.

    When I use the join in a select query, it works.

    But when I use the join as inline in an update statement I get the error ORA-01779.

    When I remove the '+ 0' the update statement works. (The column is unique in table B).

    Any ideas why this happens?

    Thank you very much in advance for any help.

    Hartmut cordially

    You plan to use a NO_INDEX hint as shown here: http://www.psoug.org/reference/hints.html

  • JOIN the question... Join two tables without omitting lines

    I came across a problem that should be an easy fix (I hope), but I'm having a hard time to come up with a solution.

    Basically I have two tables, one with the actual amounts with the budget. I have to write a sql statement select that joins these tables together and includes all of their lines. I was able to join the tables by using JOIN, LEFT JOIN and RIGHT JOIN, but it always fails the lines I need.

    Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity, I built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables are not quite that simple, but I don't think it was relavent to this issue.

    AMOUNT_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT

    2013

    111111555555000010020131111115555551000100201311111155555520001002013111111555555300010020131111115555554000100

    BUDGET_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT BUDGET

    2013

    1111115555553000200201311111155555540002002013111111555555500020020131111115555556000200

    Here's what I hope. Note that SUB_ACCOUNTs 0000, 1000, and 2000 show without budget amounts since there is not a corresponding line in the BUDGET_TABLE. And same for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amount because there is not a corresponding line in the AMOUNT_TABLE.

    (exit)

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    201311111155555500001000
    201311111155555510001000
    201311111155555520001000
    20131111115555553000100200
    20131111115555554000100200
    201311111155555550000200
    201311111155555560000200

    If all goes well, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.

    Use the join ANSI - FULL OUTER JOIN syntax:

    with amount_table like)

    Select fiscal_year 2013, 1 period, 11111 acct_unit, 555555, 0000 sub_account, amount 100 of all the double union

    Select 2013,1,11111,555555,1000,100 from all the double union

    Select 2013,1,11111,555555,2000,100 from all the double union

    Select 2013,1,11111,555555,3000,100 from all the double union

    Select double 2013,1,11111,555555,4000,100

    ),

    budget_table like)

    Select 1 time, 11111 acct_unit, account 555555, sub_account 3000, 2013 fiscal_year, budget of 200 Union double all the

    Select 2013,1,11111,555555,4000,200 from all the double union

    Select 2013,1,11111,555555,5000,200 from all the double union

    Select double 2013,1,11111,555555,6000,200

    )

    Select nvl (a.fiscal_year, b.fiscal_year) fiscal_year,

    period of NVL (a.period, b.period),

    NVL (a.acct_unit, b.acct_unit) acct_unit.

    account of NVL (a.Account, b.Account),

    NVL (a.sub_account, b.sub_account) sub_account.

    Amount NVL(a.amount,0),

    NVL(b.budget,0) budget

    of amount_table one

    full join

    budget_table b

    on)

    a.Fiscal_Year = b.fiscal_year

    and

    a.period = b.period

    and

    a.acct_unit = b.acct_unit

    and

    a.Account = b.account

    and

    a.sub_account = b.sub_account

    )

    /

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    ----------- ---------- ---------- ---------- ----------- ---------- ----------
    2013 1 11111 555555 0 100 0
    2013 1 11111 555555 1000 100 0
    2013 1 11111 555555 2000 100 0
    2013 1 11111 555555 3000 100 200
    2013 1 11111 555555 4000 100 200
    2013 1 11111 555555 6000 0 200
    2013 1 11111 555555 5000 0 200

    7 selected lines.

    SQL >

    SY.

  • How to join two tables without constraints?

    I want to get back the tables to join without constraints!

    Table 1:

    get 100
    101 wet
    series 102

    and

    Table 2:

    10 xxx movies
    11 yyy
    12 zzz
    QUERY 1:

    SELECT * FROM TO LEAVE P, CUSTES C
    WHERE (P.ID, P.NAME, C.ID, C.NAME) IN (SELECT P1.ID, P1.NAME, C1.ID, C1.NAME
    OF P1, C1 CUSTES TO GO)

    I got the result like this,

    ID ID NAME
    101 wet 10 xxx
    zzz 101 wet 12
    YYY 101 wet 11
    Get 100 10 xxx
    102 the yyy 11 value
    series 102 10 xxx
    100 get 11 yyy
    100 get 12 zzz
    102 the value 12 zzz

    All ranks was sent three times! but I need to write once.

    QUERY 2:

    Select id as pid, name as the name of go
    Union
    Select id as pid, name as the name of custes;

    QUERY2 OUTPUT IS.

    NAME OF PID
    10 xxx movies
    11 yyy
    12 zzz
    get 100
    101 wet
    series 102

    In the 2nd query get the attached files of the two tables. But my need is two tables record to display like this

    ID NAME NAME_1 ID_1
    Get 10 xxx 100
    wet 11 101 yyy
    set of 12 zzz 102

    I'm looking for is, I want to join in parallel columns in my trips!

    Is there a source... ? or the same code is happy...!

    Something like that?

    WITH t1 AS (SELECT '100' id, 'get' name FROM DUAL
                UNION
                SELECT '101', 'wet' FROM DUAL
                UNION
                SELECT '102', 'set' FROM DUAL),
         t2 AS (SELECT '10' id, 'xxx' name FROM DUAL
                UNION
                SELECT '11', 'yyy' FROM DUAL
                UNION
                SELECT '12', 'zzz' FROM DUAL)
    SELECT id,
           name,
           (SELECT id
              FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
             WHERE t_in.rw = t_out.rw)
              id_1,
           (SELECT name
              FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
             WHERE t_in.rw = t_out.rw)
              name_1
      FROM (SELECT ID, name, ROWNUM rw FROM t1) t_out
    
    SQL> WITH t1 AS (SELECT '100' id, 'get' name FROM DUAL
      2              UNION
      3              SELECT '101', 'wet' FROM DUAL
      4              UNION
      5              SELECT '102', 'set' FROM DUAL),
      6       t2 AS (SELECT '10' id, 'xxx' name FROM DUAL
      7              UNION
      8              SELECT '11', 'yyy' FROM DUAL
      9              UNION
     10              SELECT '12', 'zzz' FROM DUAL)
     11  SELECT id,
     12         name,
     13         (SELECT id
     14            FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
     15           WHERE t_in.rw = t_out.rw)
     16            id_1,
     17         (SELECT name
     18            FROM (SELECT ID, name, ROWNUM rw FROM t2) t_in
     19           WHERE t_in.rw = t_out.rw)
     20            name_1
     21    FROM (SELECT ID, name, ROWNUM rw FROM t1) t_out;
    
    ID  NAME ID_1 NAME_1
    --- --- -- ---
    100 get 10 xxx
    101 wet 11 yyy
    102 set 12 zzz
    
    SQL>
    

    The number of rows in the tables are the same?

  • Please, help me to join of two tables?

    Hello..

    I'm using oracle 11g.

    I have two tables with below description

    1.esb_v_study_personnel

    study_code_alias varchar2,

    Site_ID number,

    role_at_site_level_desc varchar2

    2 esb_v_study_site

    study_code_alias varchar2

    Site_ID

    I'm counting the role_at_site_level_desc where it is'Monitor' or 'primary monitor'

    So I wrote the following query

    Select study_code_alias, site_id,.

    no_of_study_monitors (role_at_site_lvl_desc)

    esb_v_study_site_personnel

    study_code_alias IN & arg_trial_code

    role_at_site_lvl_desc in ()"Monitor" "Main screen"()

    Group of study_code_alias, study_site_id

    order by study_site_id

    using the above, I'm getting lines of 1617.

    but I want to map the resultant site_id

    esb_v_study_site with lines of 1647. If I want to get all the site_id in esb_v_study_site table mapping to above query.

    Can you guide me on this point.

    I tried with a left outer join, but still iam getting lines of 1617.

    Select study_code_alias,

    no_of_study_monitors (role_at_site_lvl_desc)

    esb_v_study_site_personnel

    study_code_alias IN & arg_trial_code

    role_at_site_lvl_desc in ()"Monitor" "Main screen"()

    Group of study_code_alias, study_site_id

    order of study_site_id) a

    LEFT OUTER JOIN

    ON a.trial_no = d.trial_no et a.study_site_id = d.study_site_id

    d.study_code_alias in & arg_trial_code

    Group by d.study_code_alias, d.study_site_id, a.no_of_study_monitors

    order by d.study_site_id

    Please help me on this?

    I'm not quite sure, because your query seems to us of small missing pieces. He was probably down during some copy & paste on this forum.

    I guess the reason is that the left join is performed after the group where the count on the column does not count NULL values that might be created by the outer join.

    Maybe you can start with the following query and give us the results and tell us if it is always wrong and what the outcome would be expected.

    example (not tested the syntax)

    select  d.study_code_alias
        ,d.site_id
       , count(a.role_at_site_lvl_desc) no_of_study_monitors
       , count(distinct a.role_at_site_lvl_desc) no2
       , count(*) no3
    from esb_v_study_site d
    left join esb_v_study_site_personnel a on a.trial_no=d.trial_no and a.study_site_id=d.study_site_id and a.role_at_site_lvl_desc in ('Field Monitor','Primary Monitor')
    where d.study_code_alias IN (&arg_trial_code)
    group by d.study_code_alias,d.study_site_id
    order by d.study_site_id;
    

    BTW: If you read the FAQ in the upper right corner, here, he said how well sql zip code search.

  • help the join of two tables

    Hello

    I need your help in the script below:

    I have two tables.

    My "table1" table contains the data below:

    Code:

    Name, Value
    ------------
    12 A, 1
    12 B, 1
    12 C, 1



    Table2 contains the following data:

    Code:

    value, result
    ------------
    1.12
    1.24
    1.56
    1 423
    1.32
    1, 3




    I need to join based on a field value.

    My result is:

    Code:


    NAME, VALUE, RESULT
    -------------------------
    12 A, 1, 12
    12 B, 1: 24
    12 C, 1, 56
    12d, 1, 423
    12TH, 1, 32
    12F, 1, 3





    Based on the number of records in the second table, it must add A to Z at the end of the name field. The number of records exceeds no more than 26. How can we achieve this?


    _________________

    Thank you
    Pocard

    OK, now you give other useful information - that there always will be combinations of amounts in table2 to match values in table1. (It is difficult to help when you say the specs one both :-))

    But it is not easy, because the code should really try to consider all combinations and then 'choose the right' - it's easy for us humans, but not easy to code in the programming logic.
    I made an attempt:

    SQL> set linesize 120
    SQL> with table1 as (
      2     select 'A1' name, 123 id, 150 value from dual union all
      3     select 'A2' name, 123 id, 200 value from dual union all
      4     select 'A3' name, 123 id, 300 value from dual
      5  ), table2 as (
      6     select 123 id, 100 value from dual union all
      7     select 123 id, 100 value from dual union all
      8     select 123 id, 50  value from dual union all
      9     select 123 id, 100 value from dual union all
     10     select 123 id, 100 value from dual union all
     11     select 123 id, 100 value from dual union all
     12     select 123 id, 100 value from dual
     13  )
     14  --
     15  -- End of test data
     16  --
     17  select
     18  t1.id, t1.name, t1.value, t2.value,
     19  t1.rn, t1.minval, t1.maxval,
     20  t2.rn, t2.sumval
     21  from (
     22     select
     23     tab1.*,
     24     nvl(sum(tab1.value) over (
     25        partition by tab1.id
     26        order by tab1.rn
     27        rows between unbounded preceding and 1 preceding
     28     ),0) minval,
     29     sum(tab1.value) over (
     30        partition by tab1.id
     31        order by tab1.rn
     32        rows between unbounded preceding and current row
     33     ) maxval
     34     from (
     35        select
     36        table1.*,
     37        row_number() over (
     38           partition by table1.id
     39           order by table1.value desc
     40        ) rn
     41        from table1
     42     ) tab1
     43  ) t1
     44  join (
     45     select
     46     tab2.*,
     47     sum(tab2.value) over (
     48        partition by tab2.id
     49        order by tab2.rn
     50     ) sumval
     51     from (
     52        select
     53        table2.*,
     54        row_number() over (
     55           partition by table2.id
     56           order by table2.value desc
     57        ) rn
     58        from table2
     59     ) tab2
     60  ) t2
     61  on (t2.id = t1.id)
     62  where t2.sumval > t1.minval
     63  and t2.sumval <= t1.maxval
     64  order by
     65  t1.id,
     66  t1.rn,
     67  t2.rn
     68  ;
    
            ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
    ---------- -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
           123 A3        300        100          1          0        300          1        100
           123 A3        300        100          1          0        300          2        200
           123 A3        300        100          1          0        300          3        300
           123 A2        200        100          2        300        500          4        400
           123 A2        200        100          2        300        500          5        500
           123 A1        150        100          3        500        650          6        600
           123 A1        150         50          3        500        650          7        650
    
    7 rows selected.
    

    It doesn't seem to work for your sample data, but it is much too simple a rule at work in general. My "rule" is simply of sorts data according to the value descending and adding up to what 'enough' of values have been added.

    Consider this example of data instead of this:

    SQL> with table1 as (
      2     select 'A1' name, 1 id, 100 value from dual union all
      3     select 'A2' name, 1 id, 200 value from dual union all
      4     select 'A3' name, 1 id, 300 value from dual union all
      5     select 'B1' name, 2 id, 100 value from dual union all
      6     select 'B2' name, 2 id, 200 value from dual
      7  ), table2 as (
      8     select 1 id, 25  value from dual union all
      9     select 1 id, 75  value from dual union all
     10     select 1 id, 50  value from dual union all
     11     select 1 id, 50  value from dual union all
     12     select 1 id, 175 value from dual union all
     13     select 1 id, 225 value from dual union all
     14     select 2 id, 25  value from dual union all
     15     select 2 id, 50  value from dual union all
     16     select 2 id, 75  value from dual union all
     17     select 2 id, 100 value from dual union all
     18     select 2 id, 50  value from dual
     19  )
     20  --
     21  -- End of test data
     22  --
     23  select
     24  t1.id, t1.name, t1.value, t2.value,
     25  t1.rn, t1.minval, t1.maxval,
     26  t2.rn, t2.sumval
     27  from (
     28     select
     29     tab1.*,
     30     nvl(sum(tab1.value) over (
     31        partition by tab1.id
     32        order by tab1.rn
     33        rows between unbounded preceding and 1 preceding
     34     ),0) minval,
     35     sum(tab1.value) over (
     36        partition by tab1.id
     37        order by tab1.rn
     38        rows between unbounded preceding and current row
     39     ) maxval
     40     from (
     41        select
     42        table1.*,
     43        row_number() over (
     44           partition by table1.id
     45           order by table1.value desc
     46        ) rn
     47        from table1
     48     ) tab1
     49  ) t1
     50  join (
     51     select
     52     tab2.*,
     53     sum(tab2.value) over (
     54        partition by tab2.id
     55        order by tab2.rn
     56     ) sumval
     57     from (
     58        select
     59        table2.*,
     60        row_number() over (
     61           partition by table2.id
     62           order by table2.value desc
     63        ) rn
     64        from table2
     65     ) tab2
     66  ) t2
     67  on (t2.id = t1.id)
     68  where t2.sumval > t1.minval
     69  and t2.sumval <= t1.maxval
     70  order by
     71  t1.id,
     72  t1.rn,
     73  t2.rn
     74  ;
    
            ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
    ---------- -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
             1 A3        300        225          1          0        300          1        225
             1 A2        200        175          2        300        500          2        400
             1 A2        200         75          2        300        500          3        475
             1 A1        100         50          3        500        600          4        525
             1 A1        100         50          3        500        600          5        575
             1 A1        100         25          3        500        600          6        600
             2 B2        200        100          1          0        200          1        100
             2 B2        200         75          1          0        200          2        175
             2 B1        100         50          2        200        300          3        225
             2 B1        100         50          2        200        300          4        275
             2 B1        100         25          2        200        300          5        300
    
    11 rows selected.
    

    In this data set simple ranking by value won't work - it should have been A3: (225,75), A2: (175,25) and A1: (50.50).

    I can't really think of a reasonably easy way to do this in SQL only. Maybe using the clause TYPE would be possible, but not negligible. It is possible, it would be easier to solve this problem in PL/SQL in iterating through a few tables and intelligently to try different combinations, rather than creating all combinations in a huge piece of brute force SQL.

    I'm sorry, Pandeesh, but I can't think a solution easily.
    I might be able to do something, if I fiddled with the problem for a few days, but that would be beyond the scope of this forum. It would be a consultation of employment rather than a little help from the forum :-)

  • Join of two tables

    Hi all

    I have two tables - TableA and TableB

    I need all these records in TableA that have no matching records in TableB based on Key1, Key2, and Key3 and process them further.

    Can someone help pls?

    Hello 954475

    Try this:

    SELECT A.*

    FROM TableA A

    WHERE DOES NOT EXIST (SELECT 1

    FROM TableB B

    WHERE A.Key1 = B.Key1

    AND A.Key2 = B.Key2

    AND A.Key3 = B.Key3

    )

    ;

    I hope that helps!

  • Immagerie two tables without a CARPENTER

    Hello
    I had a little problem. I want to combine the two tables. But I don't need a Carpenter, cause that would give me wrong combined values.
    I have a table working_hours which has the actual hours of work of employees. And a table times_absent that the absent employee time.
    The two tables have the date and hours actual work and absent in addition to other tings inside.
    Simple I want to combine these two tables in a large table.

    Example:
    Table working_hours:
    Name - Date - hours-...
    Mr.A - 2.5.2011 - 8-...
    Mr.B - 2.5.2011 - 6-...
    C 2.5.2011 - 7-...

    Table times_absent:
    Name - Date - day-...
    Mr.A - 3.5.2011 - 1-...
    Mr.B - 3.5.2011 - 2-...
    Mr.B - 4.5.2011 - 2-...


    New Table:
    Name - Date - Working_Hours - Absent_Days-
    Mr.A - 2.5.2011 - 8 - null - or some sort of dummy value XXX
    Mr.A - 3.5.2011 - null-- 1
    Mr.B - 2.5.2011 - 6 - null.
    Mr.B - 3.5.2011 - null - 2-
    Mr.B - 4.5.2011 - null - 2-

    and so we.

    Is there a possibility in the OWB to perform this task?

    THX

    I did not understand your answer, but the OPERATOR PUT a couple IN a GROUP. What you need to do is connect your table 1 to table 2 for INgroup2 and INgroup1 (the two tables must have the same number and type of columns and the order is also important) and set your SET UNION operator, and that's all.

  • Left join between two tables using two different conditions

    I have following three tables with their data, as shown below.

    CREATE TABLE TIREMASTERPROCESS_TEMP
    (
    PRODUCTIONCODE TANK (12 BYTES),
    FIELDNAME CHAR (12 BYTES),
    DATACHR VARCHAR2 (60 BYTE),
    REVISIONNO TANK (3 BYTES),
    DATANUM NUMBER (9.4)
    )
    Whether the table c. and its sample data are like

    FIELDNAME DATACHR REVISIONNO DATANUM PRODUCTIONCODE
    AB No. Nch 1 100 0
    AB No. Nch 1 108 0
    AB No.-of-Nch 1 1 0
    Ass42 teased dishes 1 0
    Ass42 BTDrumNo1 BTD-051 1 0
    AB53 BTDrumNo1 BTD-051 104 0


    CREATE TABLE materialcode
    (
    UPPERMATERIALCODE CHAR (20),
    PROCESSNO TANK (3),
    PROCESSADOPTDATE TANK (9)

    )
    Whether the table b. and its sample data are like

    UPPERMATERIALCODE PROCESSNO PROCESSADOPTDATE
    Ass42 1 20120717
    AB53 108 20121121
    111 20111104 AS05
    104 20120928 AS30


    CREATE TABLE BUILDINGSCHEDULEMASTER
    (
    BUILDINGSIZE TANK (5 BYTES),
    GTCODE FLOAT (4 BYTES),
    TIREPERCART NUMBER (3.0).
    BUILDINGLOT NUMBER (3.0)
    )
    Whether table and its sample data are like

    BUILDINGSIZE GTCODE TIREPERCART BUILDINGLOT
    AB42A 4 12 ass42
    AB53A 4 88 AB53
    AS30A AS30 4 80
    BF03A 1 90 BF03


    Now, I need to get some data in these fields by using the suite of mappings.

    « PR_ » || Trim (a.BUILDINGSIZE) | ' / MPL2' Processid,--PRIMARY KEY
    TO_DATE (substr (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') starteff, to_date (SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') startDate.
    b.PROCESSNO revisioncodeid,
    a.BUILDINGLOT tirepercart ,
    CASE WHEN c.FIELDNAME = 'BTDrumNo1' then c.DATACHR end drumtype1.
    BOX WHEN (trim (C.DATACHR) = '1' and trim (C.FIELDNAME) = "No. Nch") and THEN click 'YES '.
    ANOTHER 'NO '.
    END may-BUG,
    case
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR = 'Use' THEN on 'YES '.
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR <>'Use' THEN 'NO '.
    fine wavy


    Now for the tables A and B I have the simple join as condition

    a.GTCODE = b.UPPERMATERIALCODE

    But I have to use two different left join conditions to join the table B and C to calculate the RESP fields according to the condition.
    Now, I have to use

    (trim (b.UPPERMATERIALCODE)). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    condition to get the data for the WAVY and DRUMTYPE1 fields.

    But at the same time, I have to use

    substr (Trim (b.UPPERMATERIALCODE), 1, 2). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    conition to derive the CHAFER field.

    And for this reason I am come so many duplicates and do not correct results for JUNEBUG, WAVY, DRUMTYPE1, and STARTDATE field.

    I need some advice as how can I do so that I get the correct results without duplicates for the PRIMARY KEY.

    Thank you

    Mahesh

    It would have been easier to answer if you gave us your example query that gives incorrect results - which both show us what you are doing and give us a starting point.
    Insert instructions for data, rather than only the data would have helped too, making it more quick to test this point.
    You do not show what you have done with your two outer join criteria, but I think you need to list TIREMASTERPROCESS_TEMP in your query twice, with alias names. Here's what I did:

    select a.BUILDINGSIZE, a.GTCODE, b.PROCESSNO ,  c1.FIELDNAME, c1.DATACHR, C2.FIELDNAME, C2.DATACHR
    , CASE WHEN c1.FIELDNAME='BTDrumNo1' then c1.DATACHR end drumtype1
    , CASE WHEN (trim(c2.DATACHR) = '1' and trim(c2.FIELDNAME) = 'No-of-Nch') THEN 'YES' ELSE 'NO' END CHAFER
    , case when c1.FIELDNAME='Wavy' AND c1.DATACHR='Use' THEN 'YES'
           when c1.FIELDNAME='Wavy' then 'NO' else null end wavy
    from BUILDINGSCHEDULEMASTER        A
    join materialcode b on a.GTCODE=b.UPPERMATERIALCODE
    left outer join TIREMASTERPROCESS_TEMP c1
       ON trim(b.UPPERMATERIALCODE)||'-'||trim(b.PROCESSNO) = trim(c1.PRODUCTIONCODE)||'-'||trim(c1.REVISIONNO)
    left outer join TIREMASTERPROCESS_TEMP c2
       ON substr(trim(b.UPPERMATERIALCODE),1,2)||'-'||trim(b.PROCESSNO) = trim(c2.PRODUCTIONCODE)||'-'||trim(c2.REVISIONNO)
    

    C1 is an alias for the TIREMASTERPROCESS_TEMP line which is necessary for drumtype1 and wavy, c2 is an alias for the TIREMASTERPROCESS_TEMP line required for JuneBug. There was some minor errors in your calculations of field I tried to correct.

    The results are:

    BUILD GTCO PRO FIELDNAME    DATACHR    FIELDNAME    DATACHR    DRUMTYPE1  CHA WAV
    ----- ---- --- ------------ ---------- ------------ ---------- ---------- --- ---
    AB53A AB53 108                         No-of-Nch    1                     YES
    AB42A AB42 1   BTDrumNo1    BTD-051    No-of-Nch    1          BTD-051    YES
    AB42A AB42 1   Wavy         NotUse     No-of-Nch    1                     YES NO
    AS30A AS30 104                                                            NO
    

    Hope this helps,
    David

  • Several foreign key joins between two tables

    Hello

    I have a question about the creation of a repository.

    I have a date and a fact dimension. The fact table has about 10 columns in foreign key to the date Dimension.

    In this case I should create 10 aliases to create joins in the physical layer and MDB or y at - it another way to handle this situation.

    I ask this question because 10 aliases can get very confusing for me at the later stage of time when creating reports.

    With the help of OBIEE 10.1.3

    If you want to see in the industry as
    End date, start date, date etc. nearby
    you need to create 10 aliases for this purpose in the physical layer, make them drag in MDB and model, and then drag to the area of topic

    Score pls correct/good

  • How do good group when the join of two tables?

    Hi all

    The slot using join query, I'd like to get an output will depend on the number of 'Classes' (for example: if I want the result for 15 classes, then, he must return to 16 lines from 0 to 16).
    I n query below, I use the group as
    "GROUP BY report_parameters.report_parameter_value  "
    .

    Error that says "this is not group by expression.

    If I have commented here, here he returns 320 rows instead of 16 ranks.

    Could someone help me?

     SELECT 'SUM('
        || 'CASE '
        || 'WHEN edr_class_by_gvw_report_data.bin_id >= ' || report_range_parameters.report_parameter_min_value || ' 
             AND edr_class_by_gvw_report_data.bin_id  < ' || report_range_parameters.report_parameter_max_value || '
            THEN edr_class_by_gvw_report_data.bin_value '    
        || 'ELSE 0 '
        || 'END '
        || ') "Class ' || report_parameters.report_parameter_value || '" '    
          FROM report_parameters
          JOIN report_range_parameters
            ON report_parameters.report_parameter_id = report_range_parameters.report_parameter_id 
         WHERE report_range_parameters.report_parameter_id    = 2316    
           AND report_range_parameters.report_parameter_group = 'GVW_GROUP'
           AND report_range_parameters.report_parameter_name  = 'GVW_NAME'
           AND report_parameters.report_parameter_group = 'CLASS'
           AND report_parameters.report_parameter_name  = 'CLASS' 
         GROUP BY
          report_parameters.report_parameter_value  
         ORDER BY  report_range_parameters.report_parameter_min_value ASC;
    Thank you.

    Published by: user10641405 on June 11, 2009 12:23

    Published by: user10641405 on June 11, 2009 12:30

    Hello

    Let me explain what I'm trying to do.
    I want to write a query that produces this output:

    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 0 AND edr_class_by_gvw_report_data.gvw  < 5 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 0"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 5 AND edr_class_by_gvw_report_data.gvw  < 10 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 1"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 10 AND edr_class_by_gvw_report_data.gvw  < 15 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 2"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 15 AND edr_class_by_gvw_report_data.gvw  < 20 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 3"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 20 AND edr_class_by_gvw_report_data.gvw  < 25 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 4"
    

    using data from tables report_parameters and report_range_parameters, which are like your tables.
    Right now, I don't have report_parameters and report_range_parameters tables.
    I need to create and put the data in them that is like your data.
    If I have the same data you have, and if I can produce the results that you want from the data, so I'll post my query, and you can use it.

    I do not see how to INSERT statements like this:

    INSERT INTO "class_by_gvw_report_data"
              SELECT site_id,
                  site_lane_id,
                 site_direction_id,
                site_direction_name,
                  bin_start_date_time,
                  bin_end_date_time,
                  bin_id,
                bin_value
             FROM "class_by_gvw_bin_data"
    

    can help me. Is the table "class_by_gvw_report_data" invloved in this problem? Is this the same as report_parameters or report_range_parameters? If Yes, I need to create it, and put the data into it, so to use the above statement I need all data of "class_by_gvw_bin_data".

    I need to have something that I can run, so that my paintings will have sample data which would result in the desired output.
    I need the CREATE TABLE statements, but I can probably guess what they should be if I have your data. If this isn't the case, I will seek further clarification later.
    I can't guess what your data, and why is it causing problems. If I just do a few data, LII is virtually no chance he's going against hepatitis has a relationship between the tables that are causing you problems of the same nature.

    Please post INSERT statements that I can run and produce the same type of data that is causing problems.

  • Join of two tables or more in a Ref Cursor columns

    Hi all

    I try to display data columns from two different tables in a cursor.

    Here is the code I am trying...
        DECLARE
       v_dname VARCHAR2(100); 
       v_query VARCHAR2(4000); 
       TYPE ref_cur IS REF CURSOR; 
       v_ref ref_cur; 
       
       d_cname VARCHAR2(100); 
       d_salary NUMBER; 
       --v_dname VARCHAR2(100); 
     
    BEGIN 
       SELECT dname
         INTO v_dname
         FROM dept 
         WHERE deptno = 20; 
         
       v_query := 'SELECT v_dname, a.* 
                      FROM customer a ';
                      
        OPEN v_ref FOR v_query; 
        
        LOOP
           FETCH v_ref INTO v_dname, d_cname, d_salary; 
           EXIT WHEN v_ref%notfound; 
           dbms_output.put_line(v_dname||' '|| d_cname||' '|| d_salary); 
        END LOOP; 
    END; 
    /
    
    I'm trying to get the output as below 
    
    RESEARCH   Dave        9000
    RESEARCH   Amy             10000
    RESEARCH   Anita     11000
    RESEARCH   Bob             12000
    RESEARCH   Marwin     5000
    RESEARCH   Shawn     12000
    RESEARCH   chris              8000
    RESEARCH   Henrik      14000
    RESEARCH   Tricia     7000
    RESEARCH   Nita             9000
    How can this be achieved?
    Thank you.

    Published by: polasa on October 31, 2008 10:25

    polasa wrote:
    I'm v_dname as invalid identifier.

    Using the code of origin you have validated, right? This is because you are using dynamic SQL statements where you shouldn't be (the local variable v_dname does not exist under your dynamic SQL is running in).

    Justin

Maybe you are looking for