Integrating the two parts of a union select statement...

Hi everybody ,
I have a query such as the one follows...:
SELECT TMHMA , DATES , COUNT(EXETASI)
FROM PARAGG_LAB_TESTS_LOCAL_MS PAR_TESTS_MS , PARAGG_LAB_TESTS_LOCAL PAR_TESTS_DET
WHERE PAR_TESTS_MS.BARCODE=PAR_TESTS_DET.BARCODE
GROUP BY TMHMA , DATES
UNION
SELECT TMHMA , DATES , SUM(NUM_TESTS)
FROM NUM_TESTS_PROFILE ,
PARAGG_LAB_PROFILES_LOCAL_MS PAR_PROFILE_MS , PARAGG_LAB_PROFILES_LOCAL PAR_PROFILE_DET
WHERE PAR_PROFILE_MS.BARCODE=PAR_PROFILE_DET.BARCODE AND
PAR_PROFILE_DET.PROFILE=NUM_TESTS_PROFILE.CODE_PROFILE
GROUP BY TMHMA , DATES
Is this possible to integrate the two parts of the above union sql statement into one (without using union) and compute the result of COUNT(EXETASI)+SUM(NUM_TESTS)..????
Thanks , a lot
Simon

Hi , Jameel
it is not correct because the columns more than one table has the columns TMHMA and DATES . To indicate this , i rewrite the query...
SELECT PAR_TESTS_MS.TMHMA , PAR_TESTS_MS.DATES , COUNT(EXETASI)
FROM PARAGG_LAB_TESTS_LOCAL_MS PAR_TESTS_MS , PARAGG_LAB_TESTS_LOCAL PAR_TESTS_DET
WHERE PAR_TESTS_MS.BARCODE=PAR_TESTS_DET.BARCODE
GROUP BY TMHMA , DATES
UNION
SELECT PAR_PROFILE_MS.TMHMA , PAR_PROFILE_MS.DATES , SUM(NUM_TESTS)
FROM NUM_TESTS_PROFILE ,
PARAGG_LAB_PROFILES_LOCAL_MS PAR_PROFILE_MS , PARAGG_LAB_PROFILES_LOCAL PAR_PROFILE_DET
WHERE PAR_PROFILE_MS.BARCODE=PAR_PROFILE_DET.BARCODE AND
PAR_PROFILE_DET.PROFILE=NUM_TESTS_PROFILE.CODE_PROFILE
GROUP BY TMHMA , DATES
and the results
TMHMA DATES COUNT(EXETASI)
11 19/8/2005 1
11 15/9/2005 4
11 15/9/2005 57
11 16/9/2005 58
11 10/10/2005 4
11 10/10/2005 72
11 14/10/2005 3
11 14/10/2005 160
11 7/4/2006 2
11 7/4/2006 53
11 8/4/2006 2
11 8/4/2006 61
11 9/4/2006 2
11 9/4/2006 31
209 30/4/2006 3
209 30/4/2006 31
209 8/5/2006 4
209 8/5/2006 31
88 20/10/2005 2
88 20/10/2005 59
and the expected results.....
TMHMA DATES COUNT(EXETASI)
11 19/8/2005 1
11 15/9/2005 61
11 16/9/2005 58
11 10/10/2005 76
11 14/10/2005 163
11 7/4/2006 55
11 8/4/2006 63b]
11 9/4/2006 [b]33
209 30/4/2006 34
209 8/5/2006 35
88 20/10/2005 61
Thanks , a lot
Simon

Similar Messages

  • I am trying to download Elements 12. I've downloaded the two parts on your web site but when I run the second part it comes up with a message saying 'The file archive part of Adobe Photoshp Elements 12 is missing...'. What shoudl I do?

    I am trying to download Elements 12. I've downloaded the two parts on your web site but when I run the second part it comes up with a message saying 'The file archive part of Adobe Photoshp Elements 12 is missing...'. What should I do?

    Hello
    I’ve managed to get it to work now but not as straightforward as I’d have liked and difficult to find out how to get help.
    Rory

  • How to create a cursor on a union select statement?

    Hi,
    Using Oracle 10g RAC +ASM ( RELEASE 1002000300)
    What are is the proper way to create a cursor on a union select statement?
    Is it possible?
    code lines, Results in PLS-00201 error: sT := crsR.STATUS; sS := crsR.TIME;
    Procedure listed below:
    CREATE OR REPLACE PROCEDURE BUILD_SUMMARY IS
    CURSOR csrO IS
    SELECT
    STATUS,
    TIME
    FROM (
    SELECT
    SUBSTR(DESCRIPTION,1,50) STATUS,
    TO_CHAR(TIMESTAMP,'MM/DD/YY hh12:mi:ss') TIME
    FROM GLOBALSALES.CUBE_STATUS
    UNION ALL
    SELECT
    ' TOTAL BUILD TIME',
    TO_CHAR(TO_DATE('00:00:00','HH24:MI:SS') +(MAX(TIMESTAMP) - MIN(TIMESTAMP)), 'HH24:MI:SS')
    FROM GLOBALSALES.CUBE_STATUS);
    csrR csrO%ROWTYPE;
    sT LONG :='';
    sS LONG :='';
    BEGIN
    FOR csrR IN csrO
    LOOP
    sT := crsR.STATUS;
    sS := crsR.TIME;
    DBMS_OUTPUT.PUT_LINE(sT || ' ' || sS);
    END LOOP;
    END;
    /

    csrR csrO%ROWTYPE;
    Declares the csrR correct? Cursor Record of Cursor Object Type?That line declares one variable CSRR with your column structure described by the cursor (CSRO) type you declared above it. It means the CSRR variable has the columns you had in the SELECT statement in that cursor.
    When you run a cursor as you did you don't need to declare the record variable. Try this:
    CREATE OR REPLACE PROCEDURE build_summary IS
      CURSOR csro IS
        SELECT status, TIME
          FROM (SELECT substr(description, 1, 50) status, to_char(TIMESTAMP, 'MM/DD/YY hh12:mi:ss') TIME
                  FROM globalsales.cube_status
                UNION ALL
                SELECT ' TOTAL BUILD TIME',
                       to_char(to_date('00:00:00', 'HH24:MI:SS') + (MAX(TIMESTAMP) - MIN(TIMESTAMP)),
                               'HH24:MI:SS')
                  FROM globalsales.cube_status);
      --csrr csro%ROWTYPE;
      st   LONG := '';
      ss   LONG := '';
    BEGIN
      FOR csrr IN csro
      LOOP
        st := csrr.status;
        ss := csrr.time;
        dbms_output.put_line(st || ' ' || ss);
      END LOOP;
    END;Also why are you using LONG? It's a deprecated data type and Oracle recommends against using it. Either pick varchar2(4000) or CLOB.
    DBMS_OUTPUT.PUT_LINE will implicitly convert that LONG data type anyway.

  • Can i get an exact part of data from select statement

    hi...good afternoon...
    i want to fetch the records from a table by select statement. but i dont want to fetch the as it is record. i want to fetch a particular part of eacg record in that column.
    for example..
    table_name=tab1
    column_name=col1
    the col1 contains datas like *'customer search-cs', 'get customer-gc', 'customer delete-cd'* etc etc..
    now while writing the select query, i want to get the descriptive output as get customer, customer search, customer delete....that is i dont want the symbols..
    is it possible to get this???
    plss suggest...

    You mean like these possible ways of doing it...
    SQL> ed
    Wrote file afiedt.buf
      1* select substr('customer search-cs',1,length('customer search-cs')-3) from dual
    SQL> /
    SUBSTR('CUSTOME
    customer search
    SQL> ed
    Wrote file afiedt.buf
      1* select regexp_substr('customer search-cs','^[^-]*') from dual
    SQL> /
    REGEXP_SUBSTR('
    customer search
    SQL>

  • Use two secondary indexes in a select statement

    hi, i want to use two secondary indexes in a select statement.
    how can i do it?

    Hello,
    To do it use the WHERE stm in the same order as the secondary stm is on SE11....To check if the index is used go to tcode ST05.
    example
    select * from ztable
    WHERE BUKRS EQ 'BUK1' AND
                 ZFIELD EQ 'BOY'.
    on se11 on the ZTABLE indexes setion must have a secondary index with
    BUKRS and
    ZFIELD.
    BYE!!
    Hope this helps!!
    Gabriel

  • How to find the number of fetched lines from select statement

    Hi Experts,
    Can you tell me how to find the number of fetched lines from select statements..
    and one more thing is can you tell me how to check the written select statement or written statement is correct or not????
    Thanks in advance
    santosh

    Hi,
    Look for the system field SY_TABIX. That will contain the number of records which have been put into an internal table through a select statement.
    For ex:
    data: itab type mara occurs 0 with header line.
    Select * from mara into table itab.
    Write: Sy-tabix.
    This will give you the number of entries that has been selected.
    I am not sure what you mean by the second question. If you can let me know what you need then we might have a solution.
    Hope this helps,
    Sudhi
    Message was edited by:
            Sudhindra Chandrashekar

  • How to add the height of the bar between the two parts inside a jsplitpane?

    By default the height of the bar is so small that it's difficult for us to click the up arrow or down arrow icon to maximize or minimize the sub part.
    Is there any way to make the up and down arrow icon bigger for the vertical-layout jsplitpane?
    thanks a lot.

    See the [API documentation (link)|http://java.sun.com/javase/6/docs/api/javax/swing/JSplitPane.html#setDividerSize(int)].

  • How can i retrieve the output of procedure using a select statement ?

    Hi every one.
    this mite be dumm ?
    how can i use the output of the a procedure containing multiple rows of data in a select statement ?

    This is not  a SQL Developer question. You should ask it in the SQL and PL/SQL forum.
    The short answer is you can't.  Sounds is if you are trying to use MSSQL techniques in oracle. Learn oracle techniques

  • How imrove the peformance of VBFA table in select statements.

    Hi,
    whenever execute program in production, program execution will taking long time due to below select statement.
    Please help me how we imrove performance?
    SELECT vbelv vbeln posnn vbtyp_v
    FROM vbfa
    INTO TABLE l_i_vbfa
    FOR ALL ENTRIES IN l_i_bill_cs
    WHERE vbeln EQ l_i_bill_cs-vbeln
    AND posnn EQ '000010'
    AND vbtyp_n IN ('K', 'H'). "MOD-024--
    AND vbtyp_v IN ('K', 'H'). "MOD-024++
    SORT l_i_vbfa BY vbeln vbtyp_n.
    Regards,
    Naidu
    Moderator message: third time I have to remind you: for performance problems with VBFA table please search for previous discussions of the same topic
    Edited by: Thomas Zloch on Nov 9, 2010 12:41 PM

    Hi Naidu,
    ranges: r_vbtypv type vbfa-r_vbtyp_v.
      CLEAR r_vbtypv.
      r_vbtypv-option = 'EQ'.
      r_vbtypv-sign   = 'I'.
      r_vbtypv-low    = 'K'.
      APPEND r_vbtypv.
      CLEAR r_vbtypv.
      r_vbtypvl-option = 'EQ'.
      r_vbtypv-sign   = 'I'.
      r_vbtypv-low    = 'H'.
      APPEND r_vbtypv.
    sort l_i_bill_cs by vbenl.
    if not l_i_bill_cs[] is initial.
    SELECT vbelv vbeln posnn vbtyp_v
    FROM vbfa
    INTO TABLE l_i_vbfa
    FOR ALL ENTRIES IN l_i_bill_cs
    WHERE vbeln EQ l_i_bill_cs-vbeln
    AND posnn EQ '000010'
    AND vbtyp_v IN r_anlkl.
    endif.
    SORT l_i_vbfa BY vbeln vbtyp_n.
    Thanks,
    Nelson

  • Doing a Trace on the ARXADLMT Approval Limits form No Select statement i

    Hi I want to see the all the SQL statements executed when I open the AR Approval Limits form(ARXADLMT). So I enabled the TRACE from the Menu(supplying password) , then opened then form and did a Query-> Execute. (The base table for the block is AR_APPROVAL_USER_LIMITS.Then I turned off the trace exited applications and went to the USER_DUMP_DEST directory of the database. From here tkprofed the latest trace file .When I look at the output file I cant see any Select statements at all. At least I should be seeing a select on the base table AR_APPROVAL_USER_LIMITS. Maybe I havent understood this process well enough- what am I doing wrong.Why is the trace not containing the select statement?
    Edited by: [email protected] on 13/06/2010 03:18

    >
    ... From here tkprofed the latest trace file ...
    >
    Pl post details of your OS and EBS versions. The latest trace file may not be the correct one. Pl search the trace files for "AR_APPROVAL_USER_LIMITS" to find the right trace file.
    How To Trace From Form, Report, Program And Others In Oracle Applications (Doc ID 130182.1)
    https://supporthtml.oracle.com/ep/faces/secure/km/DocumentDisplay.jspx?id=130182.1&h=Y
    HTH
    Srini

  • Picking the right values from tables - SQL (select statement)

    Hi everyone,
    I'm facing the litlle(?) problem in Oracle environment.
    Let me explain:
    I have two tables.
    TABLE 1
    Id1 | Val1 | Id2 | Val2
    A | 44 | B | 36
    B | 36 | A | 44
    TABLE 2
    Id | Name
    A | New York
    B | Seattle
    I need to get from those tables, using SQL statement, result like this:
    Id1 | Val1 | Name1 | Id2 | Val2 | Name2
    A | 44 | New York | B | 36 | Seattle
    NOTE !! Very important!! If in table 1 we have crossed the same values in fields IdX and ValX in two rows (like in example)- just one of them should be presented as a result.
    I'm afraid it's a bit too complex. You, guys are my last hope.
    Looking forward for any solutions.
    Thanks in advance!

    jeneesh wrote:
    This can give you a startJaneesh, the OP specified that the duplication was across the ID and the VAL columns, but your solution only checks the ID's..
    SQL> ed
    Wrote file afiedt.buf
      1  with t1 as (select 'A' as id1, 44 as val1, 'A' as id2, 36 as val2 from dual union all
      2              select 'A', 36, 'A', 36 from dual)
      3      ,t2 as (select 'A' as id, 'New York' as name from dual union all
      4              select 'B', 'Seattle' from dual)
      5  -- END OF TEST DATA
      6  select distinct greatest(id1,id2) id1,
      7         case when id1 > id2 then val1 else val2 end val1,a.name name1,
      8         least(id1,id2) id2,
      9         case when id1 < id2 then val1 else val2 end val2,b.name name2
    10  from t1 t,t2 a,t2 b
    11  where greatest(id1,id2) = a.id
    12* and least(id1,id2) = b.id
    SQL> /
    I       VAL1 NAME1    I       VAL2 NAME2
    A         36 New York A         36 New York
    SQL>With this data I would have expected both rows to be returned as there is a difference in the val columns..
    SQL> ed
    Wrote file afiedt.buf
      1  with t1 as (select 'A' as id1, 44 as val1, 'A' as id2, 36 as val2 from dual union all
      2              select 'A', 36, 'A', 36 from dual)
      3      ,t2 as (select 'A' as id, 'New York' as name from dual union all
      4              select 'B', 'Seattle' from dual)
      5  -- END OF TEST DATA
      6      ,t3 as (select distinct id1, val1, id2, val2
      7              from
      8                (
      9                 select decode(switch,1,id2,id1) as id1
    10                       ,decode(switch,1,val2,val1) as val1
    11                       ,decode(switch,1,id1,id2) as id2
    12                       ,decode(switch,1,val1,val2) as val2
    13                 from (select id1, val1, id2, val2
    14                             ,case when id1||val1 > id2||val2 then 1 else 0 end as switch
    15                       from t1)
    16                )
    17             )
    18  --
    19  select t3.id1, t3.val1, t2_1.name
    20        ,t3.id2, t3.val2, t2_2.name
    21  from   t3 join t2 t2_1 on (t2_1.id = t3.id1)
    22*           join t2 t2_2 on (t2_2.id = t3.id2)
    SQL> /
    I       VAL1 NAME     I       VAL2 NAME
    A         36 New York A         36 New York
    A         36 New York A         44 New York

  • How to get the sum in BSEG table using select statement

    hai all
    i made the internal tale "itab1" .. i want to get the som  feild of  DMBTR in BSG table my code is here but its not working gave som error massage (Aggregate functions and the addition DISTINCT are not supported in field lists for pooled and cluster tables.)  plz tel me how should i do it..... i want to get the som of that feild....          
    loop at itab1
         SELECT sum( DMBTR  ) from bseg INTO itab1-DMBTR141_45
             where GJAHR = itab1-GJAHR
             and   BELNR = itab1-BELNR.
    endloop.
    regard
    nawa

    SELECT BELNR GJAHR SHKZG DMBTR
                 from bseg
                 INTO table it_bseg
                 for all entries in itab1
                 where GJAHR = itab1-GJAHR
                   and BELNR = itab1-BELNR.
    loop at it_bseg.
        IF it_bseg-shkzg = 'H'.
          it_bseg-dmbtr = it_bseg-dmbtr * ( -1 ).
        ELSE.
          it_bseg-dmbtr = it_bseg-dmbtr.
        ENDIF.
        MODIFY it_bseg.
    endloop.
    loop at it_bseg.
    READ TABLE itab1 with key belnr = it_bseg-belnr
                               gjahr = it_bseg-gjahr.
    if sy-subrc = 0.
    collect it_bseg into it_bseg_amount.
    endif.
    endloop.
    U can use the collect statement
    Regards
    Gopi

  • Trying to synch a two part audio book, but only get part 2.

    I downloaded a two part audio book from iTunes onto my iPad. I synched my iPat to my MacBook Pro but only got part 2 of the book to synch. I've confirmed that I had the book selected to synch. Thoughts?

    When you have the iPad selected, and select the audiobook to sync, can you see the two parts of the book, and are they both selected?

  • How to wait until the 1st part of the processing is done

    Hi,
    I had a hard time to combine two parts of processing in one .vi file, and thus would like to get some advice/help through the forum.
    Attached is the partial finished vi file I made. You can see that it is composed of two parts. The upper part is to run a bat file (check_result.bat), which generates a result.txt file. The lower part is to use the result.txt file as an input file, and check if the key word called "test case passed" is included in the result.txt file or not. So I want to run the upper part firstly, and then run the lower part after the upper part is finished.
    However, I don't know how to connect the two parts in a right way that the lower part only starts running after the upper part is finished. Any comments/help is highly appreciated.
    Thank you in advance.
    Xuedong 
    Attachments:
    question.vi ‏49 KB

    The magic of dataflow!
    All you need is a data dependency between the two parts. Often critical parts of each section contain error terminals, so you can just string em along in the proper order and each part must wait until the previous node has finished.
    In your particular case, the read operation has no error input, so you can recruit any other input. Create a fake data dependency by strategically placing a small sequence frame containing common code. The sequence cannot start until all code that provides imputs has finished, serving your purpose.
    Of course it seems silly to even try to read the file if the previous node failed. Right? So simply place the second part inside a case and hook it up to the error output. Now the second part (1) waits until the first part has finished AND (2) execute only of the first part succeeded. No sequence needed.
    All clear?  
    Message Edited by altenbach on 02-07-2007 02:34 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    dataflow.gif ‏4 KB
    dataflow2.gif ‏4 KB

  • How do you register iLife software that came preloaded on an iMac (I cannot seem to locate the Marketing Part Number) on the DVD?

    I just purchased an iMac with iLife and iWork preloaded.
    I wanted to register the software, but I cannot seem to locate the Marketing Part Number (MPN).  Help states the MPN is located on the product packaging near the barcode.  I can locate the barcode on the sleeve of the disc, but the MPN does not seem to be there.  Help states it starts with a letter and has the format M#####/#.  I have tried to enter each set of numbers shown, but all are invalid.

    You registered it when you registered the computer. Apple software bundled with a Mac can't be registered separately from it; that service is for standalone purchases only.
    (58748)

Maybe you are looking for

  • All CS1 apps quit when I try to launch them.

    Hello I have been told by Adobe that they cannot provide any direct assistance to me. I have tried to explain to them that I don't believe I have a technical problem with the suite, as I think it may be a licensing issue. The problem I am having is t

  • Error message when extending skype number

    Hi guys Really hope someone can help me with this. Been dealing with skype chat and email support for hours and hours over last three days with absolutely no progress. I have 8 skype numbers within my skype manager account and for some reason, one of

  • How to Use Sequence created in Oracle Database in SQL Ldr Control file

    Hi, I created a sequence in oracle database. How will use the sequence in SQL loader Control file. Thanks in advance

  • I want a new Macbook!

    Dear friends, at the beginning of the November my friends will be in New-York. I want to buy extended configuration of new MacBook Air (13 in., i7 1.8). As I understand this configuration is not available in retail Apple Stores and should be pre orde

  • Structure won't let me add characteristics

    Hi, I have 2 structures in a query but now when I try to add some particular restricted key figures it refuses to accept them? What could be the problem? Thanks