Join the two select queries

Hi all

I want to join the two select queries below
 SELECT ceil((ROUND(((H.SLURRY_VOL_ACTUAL * 5.6146)/DECODE(H.SLURRY_YIELD,0,NULL,H.SLURRY_YIELD)))*94)*F.ITEM_PERCENT/100 )MAT_ACT ,e.opn_job_desc,f.item_number
FROM   xxnp_opn_joblog_001 E,
              XXNP_OPN_JOBLOG_EST_002   F,
              XXNP_OPN_JOBLOG_STAGE_002 G,
                     XXNP_OPN_JOBLOG_SLURRY_003 H
       WHERE   E.OPN_JOB_DESC   = e.OPN_JOB_DESC
         AND E.OPN_JOBLOG_001_ID = G.OPN_JOBLOG_001_ID 
         AND G.OPN_JOBLOG_006_ID = H.OPN_JOBLOG_006_ID
      AND H.OPN_JOBLOG_007_ID = F.OPN_JOBLOG_007_ID AND F.ITEM_UOM = 'Pound' 


SELECT  ROUND(((H.SLURRY_VOL_ACTUAL * 5.6146)/H.SLURRY_YIELD))CALC_CEM ,e.opn_job_desc,f.item_number
     FROM 
              xxnp_opn_joblog_001 E,
              XXNP_OPN_JOBLOG_EST_002   F,
              XXNP_OPN_JOBLOG_STAGE_002 G,
             XXNP_OPN_JOBLOG_SLURRY_003 H
       WHERE E.OPN_JOB_DESC   = E.OPN_JOB_DESC
      AND E.OPN_JOBLOG_001_ID = G.OPN_JOBLOG_001_ID 
         AND G.OPN_JOBLOG_006_ID = H.OPN_JOBLOG_006_ID
         AND H.OPN_JOBLOG_007_ID = F.OPN_JOBLOG_007_ID
      AND F.ITEM_UOM = 'Cubic Feet'  

i tried union but calc_cem column does not come in o/p

i want these 4 columns as o/p
mat_act    calc_cem    opn_job_desc     item_number
Veuileez help
thanking in advance
concerning
oracleuser

Published by: makdutakdu on January 20, 2010 14:56
select
       case when F.ITEM_UOM = 'Cubic Feet' then
            ROUND(((H.SLURRY_VOL_ACTUAL * 5.6146)/H.SLURRY_YIELD))
       end CALC_CEM,
       case when F.ITEM_UOM =  'Pound'
            ceil((ROUND(((H.SLURRY_VOL_ACTUAL * 5.6146)/DECODE(H.SLURRY_YIELD,0,NULL,H.SLURRY_YIELD)))*94)*F.ITEM_PERCENT/100 )
       end MAT_ACT,
       e.opn_job_desc,f.item_number
     FROM xxnp_opn_joblog_001 E,
          XXNP_OPN_JOBLOG_EST_002   F,
          XXNP_OPN_JOBLOG_STAGE_002 G,
          XXNP_OPN_JOBLOG_SLURRY_003 H
      WHERE E.OPN_JOB_DESC   = E.OPN_JOB_DESC
      AND E.OPN_JOBLOG_001_ID = G.OPN_JOBLOG_001_ID
        AND G.OPN_JOBLOG_006_ID = H.OPN_JOBLOG_006_ID
        AND H.OPN_JOBLOG_007_ID = F.OPN_JOBLOG_007_ID

you want to like that?

Tags: Database

Similar Questions

  • Join the two sql queries

    Hi all

    Thank you very much for all the kind support so far.

    I have two report (sql query)

    I want to add both the sql query

    1st sql query

    select distinct(a.item_number)
          ,a.quantity - b.quantity
    from QUANTITY_ONHAND_ATP a,BACKLOG_ATP_LT_CW b
    where a.item_number = b.item_number
    order by item_number
    2nd sql query

    select distinct(wb.item_number)
           ,wb.quantity - be.quantity
           ,c.quantity - d.quantity
    from BACKLOG_WEEK_BEFORE_ATP wb
        ,BACKLOG_ATP_ET_CW be
        ,BACKLOG_WEEK_AFTER_ATP c
        ,BACKLOG_ATP_GT_CW d
    where wb.item_number = be.item_number
       and c.item_number = d.item_number
       and wb.item_number = c.item_number
       and be.item_number = c.item_number
       and wb.item_number = d.item_number
       and be.item_number = d.item_number
    order by wb.ITEM_NUMBER
    In the 1st sql query I have 129 records and in the 2nd query sql, I have 14 records. I want to combine these two sql queries. If the item_number 1st sql query is not there in 2nd and then view it as to 1 sql only.

    Any help how to do that.

    Concerning

    Published by: User_Apex on July 15, 2011 01:21

    Use the NVL function:

    select q1.item_number, WEEK_BEFORE, nvl(CURRENT_WEEK,0) CURRENT_WEEK, nvl(WEEK_AFTER,0) WEEK_AFTER
    (...)
    
  • Join the two trees connect by prior Start With and return only common records?

    Oracle 10g Release 2 (10.2)

    I have two tables which have structured data. The results, when running queries individually are correct, but I need to join tree a tree two to get only the common records between them.

    -Trees a
    SELECT ip_entity_name, entity_code, hier_level, entity_parent
    Of ip_hierarchy
    WHERE hier_level > = 3
    CONNECT BY PRIOR Entity_code = entity_parent
    START WITH entity_code = "MEWWD";

    -The two tree
    SELECT ip_entity_name, entity_code, hier_level, entity_parent
    Of ipt_hierarchy
    WHERE hier_level > = 3
    CONNECT BY PRIOR Entity_code = entity_parent
    START WITH entity_code = "IPNAM";


    If I understand correctly, the joints can not work with CONNECT BY / START WITH queries?

    A WITH clause is an option?

    If possible, I don't want to put a selection in a database to display object and join against other queries.

    Thank you.

    Hello

    jtp51 wrote:
    Oracle 10g Release 2 (10.2)
    ...
    If I understand correctly, the joints can not work with CONNECT BY / START WITH queries?

    Before Oracle 9 it was true. Since you're using Oracle 10, you can if you wish; but I'm guessing that you don't want in this case.

    A WITH clause is an option?

    If possible, I don't want to put a selection in a database to display object and join against other queries.

    Yes, a WITH clause that is an option. Viewed online, as Zhxiang has shown, are another option. Either way gives you a regular display effect without creating a database object.

    You did not show a sample and the results, so no one can tell if a join is really what you want. Other possibilities include INTERSECT or an IN subquery.

  • Combine and join the two railways closed with a straight path

    Hello

    I have two way closed and I need to combine or join them with a straight path. When I selected all and do a right click for you join, he did not join. Please see my screenshot. Thank you.

    2 closed path.jpg

    You cannot create Y-junctions.

    You can perform one of the two possbilities:

    Simply place the path open everywhere where you need and leave it there.

    convert all forms with object > path > describe stroke and then use the pathfinder functions.

  • Join the two dataProviders

    I have a table with a secondary and two axis ArrayCollections because I want the series on the left axis to update independently of the series on the right axis. Flex graphics support as a dataProvider.

    How can I join two ArrayCollections to make a data provider?

    Copy the following code uses two data providers, or maybe I don't understand the question (maybe the postcode):

    
    
    
      
      
      
      
         
            
               
            
            
                
            
            
                
                    {h1Stroke}
                
                
                    {h2Stroke}
                
            
            
               
                    
                        
                    
    
                    
                       
                    
               
               
                    
                        
                    
                    
                        
                    
               
            
         
         
      
    
    

    If this post answers your question or assistance, please mark it as such. Thank you!

    http://www.stardustsystems.com
    Adobe Flex development and Support Services

  • Joining the two points

    I would like to ask how to join two points with a line with actionscript? The points should be constantly in motion.

    You can use joinF() to draw a line from x 1, y1 to x 2, y2:

    var canvas:MovieClip=this.createEmptyMovieClip("canvas",this.getNextHighestDepth());

    function joinF(x1:Number,y1:Number,x2:Number,y2:Number):Void {}

    {with (Canvas)}

    Clear();

    lineStyle(0,0xff0000);

    moveTo(x1,y1);

    lineTo(x2,y2);

    }

    }

  • Join the two lines into one game

    Hi all

    I have a table with 1 column and records are as below. Below I show only the first 4 records to give an idea.

    Select cn from CSGL_AD_GROUP_OP_COMP_MEM_TEMP where rownum < 5;

    CN
    -------------------------------------------------------------------------------
    CN = JZJXEEW00072305, OU = computers to office, OR = Secured_Systems, OR = Computers, OR = ZJX_ARTCC, OR
    = FL, OR = ESA, OU = ATO, OU = LOB, DC = faa, DC = gov
    CN = JI90NTW00069990, OU = computers to office, OR = Secured_Systems, OR = Computers, OR = I90_TRACO, OR
    = TX, OR = CSA, OU = ATO, OU = LOB, DC = faa, DC = gov

    Now, the requirement is to concatenate the 1st and 2nd rank, concat 3rd and 4th rank, conact 5th and 6th next row and so on and put it in a new column in the same table if its possible, if not in a new table.

    How can I do this, can someone help me.

    Thank you

    Hello

    There are numerous valid aproaches, may be the last of them is more effective than the other in some cases:

    select
     c1.key
    ,C1.cn||C2.cn cn
    from
    CSGL_AD_GROUP_OP_COMP_MEM2 C1,
    CSGL_AD_GROUP_OP_COMP_MEM2 C2
    where
    C1.key+1=C2.key
    and
    mod(c1.key,2)=1
    
    select key, cn from (
    SELECT
     cn || LEAD (cn) OVER (ORDER BY key) cn
    ,key
    FROM    CSGL_AD_GROUP_OP_COMP_MEM2
    )
    where
    mod(key,2)=1
    
    select key, cn from (
    select *
    from
    CSGL_AD_GROUP_OP_COMP_MEM2 C1
    model
    dimension by (key)
    measures (cn)
    rules(
    cn[any] order by key=cn[cv()]||cn[cv()+1]
    )
    )
    where
    mod(key,2)=1
    

    concerning

  • How to cut a Lightroom 3 catalog? And join the two together...

    I did wrong in a lot of work on a batch of images in the "bad" Lightroom Catalog I'm primarily a sports photographer and that you have all the stuff of sports in a catalog and stuff not athletes in another. And I put a major sporting event - 8000 photos - in the non-sports catalog. What should I do to get out and get back to the right? I guess I could separate them by duplication of the catalogue, opening one and delete the event and openness to others and remove all the rest, but this seems a bit lengthy. And if this is the only way, how then do the event separated from catalog items in the catalog of sport?

    I'm sure it must be simpler than it looks!

    Guy

    Select the images, or record or collections you want in your catalog to another

    .

    • Then go to file, export as catalog.
    • Do not export the negatives, then uncheck this box.
    • Give it a name.
    • Export it.
    • Open your catalog on the other.
    • Select file, import from catalog and import.
    • Job done.
  • How do the query select outer join to a report of the APEX

    Hi all

    I'm Ann.

    I have a select statement that is used to calculate statistics for a month (October 2012 in this example)
    Select ph.phase_number
    sum ((case
    WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    THEN last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    Of OTHER ph.date_finished
    END)
    (-ph.date_started + 1) / count (def.def_id) as avg_days
    Ph phase_membership
    inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
    join in-house defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started < = last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    and ph.active = 1
    and UPPER (ce.court_name) LIKE '% '.
    Rollup Group (phase_number)
    ;

    The result is as below
    Phase_Number AVG_DAYS
    Phase One 8.6666666666666667
    Phase two 14.6
    Phase three 12
    11.4615365

    I have another list of selection mainly the list of months between two date value.
    Select to_char (which_month, 'LUN YYYY') as display_month
    de)
    Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
    of object
    where
    rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
    order of which_month)

    The query result is as below

    DISPLAY_MONTH

    AUGUST 2012
    SEP 2012
    OCT 2012

    Is it possible I can join these two select statement above to generate a comparable result:

    Days of month Phase number Avg
    August 2012 Phase One 8.666
    Sep 2012 Phase One 7.66
    Oct 2012 Phase One 5,66
    August 2012 Phase two 8.666
    Sep 2012 Phase two 7.66
    Oct 2012 Phase two 5,66
    August 2012 Phase three 8.666
    Sep 2012 Phase three 7.66
    Oct 2012 Phase three 5,66

    Or
    Days of month Phase number Avg
    August 2012 Phase One 8.666
    August 2012 Phase two 7.66
    August 2012 Phase three 5,66
    Sep 2012 Phase One 8.666
    Sep 2012 Phase two 7.66
    Sep 2012 Phase three 5,66
    Oct 2012 Phase One 8.666
    Oct 2012 Phase two 7.66
    Oct 2012 Phase three 5,66

    And it can be controlled by Phase number or month.
    My other colleague suggested I should use a left outer join, but after having tried many ways, I'm still stuck.

    I tried select is
    Select a.display_month, b.* in)
    Select to_char (which_month, 'LUN YYYY') as display_month
    de)
    Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
    of object
    where
    rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
    order which_month)) a left outer join

    (Select to_char (ph.date_finished, 'MY YYYY') as join_month, ph.phase_number)
    sum ((case
    WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (a.display_month, 'MY YYYY'))
    THEN last_day (TO_DATE (a.display_month, 'MY YYYY'))
    Of OTHER ph.date_finished
    END)
    (-ph.date_started + 1) / count (def.def_id) as avg_days
    Ph phase_membership
    inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
    join in-house defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started < = last_day (TO_DATE (a.display_month, 'MY YYYY'))
    and ph.active = 1
    and UPPER (ce.court_name) LIKE '% '.
    To_char (ph.date_finished, 'MY YYYY'), group (phase_number) rollup) b
    On a.display_month = b.join_month

    but then I get an error
    SQL error: ORA-00904: "A." "" DISPLAY_MONTH ": invalid identifier

    I need to view a report on the APEX with option for people to download at least format CSV.
    Already 1 inteactive report in the page, so I don't think adds another interactive report without using the iframe trick.

    If any of you have any ideas, please help.

    Thank you very much.

    Ann

    Hello Ann,.

    Frank has done a very good job. I am also impressed.

    Is in regard to your correction to his question, the problem is on this replacement you did

    last_day(TO_DATE(am.which_month,'MON YYYY'))
    

    AM.which_month is already a date type, and you don't need to convert it to this day.
    Here is the correct way:

    last_day(am.which_month)
    

    There are also sometimes with the data you've posted have no line for this month. So I also added a function NVL to display 0 under avg_days for these cases.

    Here is my corrected query:

    DEFINE startmonth = "Aug 2012";
    DEFINE endmonth   = "Oct 2012";
    WITH  all_months  AS
    (
       SELECT ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM-1) AS which_month
       ,      ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM  ) AS next_month
       from all_objects
       where
       rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1))
    )
    SELECT TO_CHAR (am.which_month, 'Mon YYYY')  AS month
         , ph.phase_number
         , NVL(sum ( (CASE
                     WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(am.which_month)
                     THEN last_day(am.which_month)
                     ELSE ph.date_finished
                  END
                 ) - ph.date_started + 1
               ) / count(def.def_id), 0) as avg_days
      FROM all_months am
           LEFT OUTER JOIN  a_phase_membership  ph  PARTITION BY (ph.phase_number)
              ON  am.which_month <= ph.date_started
              AND am.next_month  >  ph.date_started
              AND ph.date_started <= last_day(am.which_month)  -- May not be needed
              AND ph.active = 1
           LEFT OUTER JOIN  a_engagement  ce
              ON  ph.mpm_eng_id = ce.engagement_id
              AND ce.court_name IS NOT NULL  -- or something involving LIKE
           LEFT OUTER join  a_defendant     def
              ON  ce.defendant_id = def.def_id
              AND def.active = 1
     GROUP BY ROLLUP(phase_number, am.which_month)
     ORDER BY  am.which_month
            ,  ph.phase_number
    ;
    
    The output is:
    MONTH    PHASE_NUMBER           AVG_DAYS
    -------- -------------------- ----------
    Aug 2012 PHASE ONE                     0
    Aug 2012 PHASE THREE                   0
    Aug 2012 PHASE TWO                     0
    Sep 2012 PHASE ONE                    12
    Sep 2012 PHASE THREE                   1
    Sep 2012 PHASE TWO                     9
    Oct 2012 PHASE ONE                     8
    Oct 2012 PHASE THREE                   0
    Oct 2012 PHASE TWO                    14
             PHASE ONE                    11
             PHASE THREE                   1
             PHASE TWO                  11.5
                                  9.71428571
    

    I don't know if that's really what you want. In the case check it and let me know.

    Kind regards.
    Al

  • Join the path several times

    Hello

    I'm pretty new to Illustrator, but I'm learning by doing kind of guy.

    I created paths making triangles out of lines.

    I want to fill them with a solid, color that works when I join them.

    But here's the problem, if I join a triangle, I can't reach the other is because they share a path.

    as this < I > if I join one ' < I "> I can't use the right path more to create the second triangle.". "

    Is there a way to get around this or do I have him all over again

    Thanks in advance

    Before you create the first triangle, select the shared side and press command + C, command-F to paste a duplicate in place.

    Or, just select the two ends of the triangle without a third side and press command + J to join the two ends, thus creating the side missing.

  • Join the 2 queries with common group by column

    IAM trying to reach the results of 2 queries. Myu first query returns as follows.

    Like, second

    I need to show together and I wrote the request to the below:

    Select b.br_id, count (b.mech_code), sum (b.labour_cost), count (a.received_by) in table2 b, table1: a group of b.br_id;

    But it doesn't show any errors or shows no results. It just continues the treatment forever. Plese help

    Just joined the group two by queries later

    Select

    b.br_id

    b.cnt_mech_code

    b.sum_lc

    a.cnt_rcvd

    de)

    Select

    b.br_id

    count (b.mech_code) cnt_mech_code

    sum (b.labour_cost) sum_lc

    from table2 b

    B.br_id group

    ) b

    , (

    Select

    Count (a.received_by) cnt_rcvd

    Table 1A

    A.br_id group

    ) a

    where

    b.br_id = a.br_id

  • Left join of the two tables and multiple values into a single value separated by commas

    Hello

    I have following tables with their structures and their data as below.

    CREATE TABLE 'BETODI '. "" BETINFO ".

    (

    VARCHAR2 (8 BYTE) "CURRENTPRESS."

    ENABLE 'TYPEIDCONTAINER' VARCHAR2 (30 BYTE) NOT NULL

    )

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24D', 'Pensky-MARTENS');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A25D", "CMP");

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A25G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26D', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A32G", "V-BFC3");

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A32D', "V-BFC2");

    CREATE TABLE 'BETODI '. "" BETMASTER ".

    (

    ACTIVATE THE "CUREPRESS" TANK (5 BYTES) NOT NULL,

    ACTIVATE THE "TYPE" VARCHAR2 (5 BYTE) NOT NULL,

    NUMBER (5.0) "LASTPCIRIM".

    )

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A24', '45 M 8', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A25', 42 16', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A26", 16' 45, 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A27", '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A28', '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A29', '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A30', '45MCH', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A31", "45MCH", 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A32', '45MCH', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A33', '45MCH', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A34", "45MCH", 16);

    These two tables have left join as

    BETMASTER. CUREPRESS = substr (BETINFO. CURRENTPRESS, 1, 3)

    now I want to have the data in the two tables with fields Curepress, Lastpcirim, typeidcontainer.

    Also something like

    Make a group of typeidcontainer if this value is greater than 1 by press separated the values of semicolon (;)

    So, for example above, we should be given as

    A24 PMC 15; PENSKY-MARTENS

    A25 15 PMC

    A26 15 PMC

    A27 16 (NULL)

    A28 16 (NULL)

    A30 15 (NULL)

    A31 16 (NULL)

    A32 16 BFC2-V; V BFC3

    A33 16 (NULL)

    A34 16 (NULL)

    How could do?

    My current request is as

    Select distinct Curepress, lastpcirim, typeidcontainer

    BETMASTER STD left join INF BETINFO

    on the trim (STD. CUREPRESS) = substr (trim (INF. CURRENTPRESS), 1, 3)

    but I am unable to get the values separated by commas.

    Any help would be appreciated.

    Thank you

    Mahesh.

    Hi, Mahesh,

    If you want to only 1 row of output for each distinct combination of currentpress and lastpcirim?  This sounds like a job for GROUP BY.

    And you want the row to contain a list of all different typidcontainers-delimited?  This sounds like a job for the aggregate LISTAGG function.

    WITH joined_data AS

    (

    SELECT DISTINCT

    MST.curepress, mst.lastpcirim, inf.typeidcontainer

    OF betmaster STD

    LEFT JOIN betinfo ON TRIM (mst.curepress) inf = SUBSTR (TRIM (inf.currentpress)

    1

    3

    )

    )

    SELECT curepress, lastpcirim

    LISTAGG (typeidcontainer, ',')

    THE Group (ORDER BY typeidcontainer) AS container_list

    OF joined_data

    Curepress GROUP, lastpcirim

    ;

    Unfortunately, you can't say LISTAGG (DISTINCT ...), so you should always get the separate containers how you already are.  (Note that the subquery is just what you posted).

    Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.  Don't forget to tell what version of Oracle you are using.  LISTAGG was new in Oracle 11.2.

    Why not add CHECK constraints (and perhaps triggers) to your tables, so that curepress and currentpress are not stored with the head or trailing spaces?  Then you wouldn't need to use the PAD in queries like this, and your code would be simpler and more effective.

  • using outer joins if the two column is null? Use only (+)

    Hi all

    create the table xxc_tr_num (tl_number number, tr_no number tl_no_id);

    insert into xxc_tr_num values (123,100,222);

    insert into xxc_tr_num values (124,100,333);

    create the table xxc_od_tab (tl_number number, tl_id number);

    insert into xxc_od_tab values (123,001);

    insert into xxc_od_tab values (null, null);

    create table xxc_oth_tab (name varchar2 (10), number of tl_id);

    insert into xxc_oth_tab values('abc',,001);

    insert into xxc_oth_tab values (null, null);

    Wait it out put

    tr_no tl_no_id name

    100 222 abc

    100 333

    using outer joins if the two column is null? use only please of outer joins

    And I tried to use outer joins on both tl_id column but not get values and I use have County (tr_no ) > 1

    Rajesh123 wrote:

    Thank you Kiss it is not possible to use having clause?

    You need to understand the functioning of the group. If you will not be asked this question.

    Check this box

    SQL> select tr_no,
      2         tl_no_id,
      3         count(*)
      4    from xxc_tr_num a,
      5         xxc_od_tab b,
      6         xxc_oth_tab c
      7   where a.tl_number = b.tl_number(+)
      8     and b.tl_id = c.tl_id(+)
      9   group
     10      by tr_no
     11       , tl_no_id;
    
         TR_NO   TL_NO_ID   COUNT(*)
    ---------- ---------- ----------
           100        333          1
           100        222          1
    

    See what returns the count? You have grouped according to TR_NO and TL_NO_ID. You must take into consideration the TL_NO_ID just put COUNT (TR_NO) does not increase the NUMBER of the whole group. To get the NUMBER on the whole group, I used the analytical function and did. Like this, see the number of the analytical function here

    SQL> select tr_no,
      2         tl_no_id,
      3         count(*),
      4         count(*) over(partition by tr_no)
      5    from xxc_tr_num a,
      6         xxc_od_tab b,
      7         xxc_oth_tab c
      8   where a.tl_number = b.tl_number(+)
      9     and b.tl_id = c.tl_id(+)
     10   group
     11      by tr_no
     12       , tl_no_id;
    
         TR_NO   TL_NO_ID   COUNT(*) COUNT(*)OVER(PARTITIONBYTR_NO)
    ---------- ---------- ---------- ------------------------------
           100        222          1                              2
           100        333          1                              2
    

    So to answer your question, yes you can't do in the HAVING clause...

  • Please help me with the Alternative of queries to replace the UNION ALL for two queries

    Hi all

    I have the query to retrieve assets employees salary count and in so far as below:

    Select ename, emp_no, sum (sal_till_2010), sum (sal_till_2014) of

    (select emp_no, ename, salary as sal_till_2010, 0 as sal_till_2014 of employee e1

    where effective_date < = 1 January 2010 ' and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = January 1, 2010 "")

    UNION ALL

    Select ename, emp_no, 0 as sal_till_2010, salary as employee e1 sal_till_2014 - here is a dummy 0 salary until 2010 for the union of all the

    where effective_date < = 1 January 2014 "and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = 1 January 2014") "

    Group of emp_no, ename;

    In this query, I get the total salary until 2010 and until 2014 in the employee table, dates are dynamically passed to the procedure, and this can change.

    But assume the date above and let me know the alternative of queries to improve performance because I use Union ALL and read the same table twice in the above query.

    Advice me with request to read the table once to fetch the same data as the above query.

    Thanks in advance.


    Hello

    Thanks for the display of the data of the sample; It's very useful!

    I think OP wants something like this:

    WITH cutoff_dates AS

    (

    SELECT TO_DATE (January 1, 2010 ', ' DD/MM/YYYY') AS cutoff_date, 2010 UNDER the label OF dual UNION ALL

    SELECT TO_DATE (1 January 2014 ', "DD/MM/YYYY"), double 2014

    )

    SELECT e.emp_no, e.ename

    , NVL (SUM (CASE WHEN c.label = 2010 THEN e.salary END), 0) AS sal_till_2010

    , NVL (SUM (CASE WHEN c.label = 2014 THEN e.salary END), 0) AS sal_till_2014

    E employee

    JOIN cutoff_dates c ON e.effective_date<=>

    WHERE DOES NOT EXIST)

    SELECT 1

    Of employee_deletion ed

    WHERE ed.emp_no = e.emp_no

    AND ed.deletion_date<=>

    )

    E.emp_no GROUP, e.ename

    ORDER BY e.emp_no

    ;

    Output of your sample data:

    EMP_NO ENAME SAL_TILL_2010 SAL_TILL_2014

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

    1 Mickey 450 0

    2 Donald 750 0

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

Maybe you are looking for

  • M52 9210 - BIOS window - strange effect

    The bios window, called by the F1 key after power, is not displayed correctly. I use a display with resolution 1680 x 1050 and set at 1:1 scale (small window on the screen when the image has a low resolution). The monitor reports resolution 640 x 480

  • warning of avira told me that the file (autorun.inf) has blocked access for my safety, that which means that?

    Dear Microsoft Answers, After you add a desktop external hard drive, I kept getting a warning from Avira free AV that I can't access the file for my safety which means that? Thank you Bye, lelo

  • What is the correct alignment? (sandisk extreme 240 GB)

    each review seems to show an alignment of 1024 k as ssd, as here http://img.hexus.net/v2/SSD/SanDisk/Extreme240/AS-SSDb.png However my drive is set to 234496 in windows 7.  This is a new installation, the ahci enabled and the intel rst installed 10.8

  • Required expert advice.

    Hello Hope it makes you big! Looking for a good configuraiton of use at home. My main job is to browse, skyping and a work on Virtulisation by installing the VMwarelatest versions and play very few times. Alos Oracle Solaris on Virtual Box, Can you s

  • Listen to ObjectChoiceFields-based index

    HIi, I need to listen to ObjectChoiceFields based on the Index. I need to know how the default ringtone ObjectChoiceField work when we change the focus by trackball it gets the name of the targeted ring and play. is there a listener for it. I impleme