Query with sub functions

Hi Experts,
I have tried the below query with sub select function. could any one help me to fix this ?
SELECT T0.[ItemCode], T0.[Dscription], T1.[OnHand],
(Select distinct sum(T0.InQty) from OINM where T0.ItemCode = OINM.ItemCode and T0.DocDate = '2012/08/18' ) as 'OB Stock'
FROM OINM T0  INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
WHERE T1.[OnHand] > 0   GROUP BY T0.[ItemCode], T0.[Dscription],  T1.[OnHand]
thanks in advance,
Regards,
Dwarak

Hi,
This is for your Query.
SELECT T0.[ItemCode], T0.[Dscription], T1.[OnHand],
(Select distinct sum(T0.InQty) from OINM t0 where T0.ItemCode = T0.ItemCode and T0.DocDate = '2012/08/18'  ) as 'OB Stock'
FROM OINM T0  INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
WHERE T1.[OnHand] > 0   GROUP BY T0.[ItemCode], T0.[Dscription],  T1.[OnHand]
Regards,
Kalaiyarasan.v

Similar Messages

  • Filter query with sub query using Dropdown box

    Dear Community,
    I have 2 queries
    1. Main Query with 2 fields:  Project | Project value
    2. Sub Query with 2 fields:  Project group | Project
    Project group can be belonging to number of projects and project can be belong to number of project group (Many to Many).
    My customer wants the main query will open without any filtering.
    When I choose project group from WAD dropdown box, the main query will filtering all the projects that belong to the project group.
    I create WAD; define dropdown box as sub query, and Analysis as main query.
    In the dropdown box I choose "data binding" char and create command "set selection state by binding" (project to project) but it doesnu2019t work. 
    I also try to do this by Replacement Path in the main query, but the variable requires the attribute will be ready for input.
    Thanks a lot
    Yaniv

    I am not sure about your comments on replacement path variable. Without having tried it, here is what I would have attempted:
    The main query needs to use a replacement path variable for Project that is replaced by the results of the sub-query. Sub-query would have a regular input variable for project group. (as a quick test, if you had one analysis item for main query with variable input enabled, it should prompt you to enter Project group).
    Now the drop-down needs to be associated with a javascript function. The javascript function needs to implement command "Set variable state" for the main query data provider to selected value of the drop-down.
    The drop-down should be associated with the sub-query data provider, just used to populate the list of values in drop-down.

  • SQL Query With analytical function

    Hi
    Below is the scenario which i am looking for in sql query using analytical functions
    I/p
    Col1
    50
    0
    -150
    -200
    300
    -100
    -300
    500
    -100
    O/p
    Col1          col2
    50                 0
    0                   0
    -150          -100
    -200              -200
    300               0
    -100              0
    -300              -100
    500               400
    -100              0Any help really appreciated
    Thanks in advance
    Edited by: unique on Aug 10, 2010 4:53 AM
    Edited by: unique on Aug 10, 2010 4:55 AM
    Edited by: unique on Aug 10, 2010 4:55 AM

    Oh,In this case,There is OLAP solution ;-)
    OLAP samples of my homepage http://www.geocities.jp/oraclesqlpuzzle/oracle-sql1-olap.html
    with work(SK,Val) as(
    select  1,  50 from dual union
    select  2,   0 from dual union
    select  3,-150 from dual union
    select  4,-200 from dual union
    select  5, 300 from dual union
    select  6,-100 from dual union
    select  7,-300 from dual union
    select  8, 500 from dual union
    select  9,-100 from dual)
    select SK,Val,GID,
    case when Val > 0
         then greatest(0,sum(Val) over(partition by GID))
         else Least(0,Val+greatest(0,sum(Val) over(partition by GID
                                     order by SK rows between unbounded preceding
                                                          and 1 preceding)))
         end as COL3
    from (select SK,Val,
          sum(greatest(0,sign(Val))) over(order by SK) as GID
          from work)
    order by SK;
    SK   VAL  GID  COL3
    1    50    1     0
    2     0    1     0
    3  -150    1  -100
    4  -200    1  -200
    5   300    2     0
    6  -100    2     0
    7  -300    2  -100
    8   500    3   400
    9  -100    3     0

  • Problem in Query with JOIN Function in OCRD CRD1 OCPR tables

    Hello Dear Forum Users,
    I want to make a query which shows me per business partner from OCRD - Addres; CRD1 - Delivery Address and from OCPR - Contactperson information
    Is it possible to show it in one row per Business Partner. Now I get (the classic problem) of several rows and a duplication of the contact persons per (delivery) address.
    My query is:
    SELECT T0.[CardCode], T0.[CardName], T1.[Address], T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_MobNr], T1.[U_OpenTijd], T1.[U_LosIns_1], T1.[U_LosIns_2],T2.[Title],  T2.[Name] as 'Voornaam', T2.[Address] as 'Achternaam', T2.[Position] as 'Functie', T2.[Tel1], T2.[Cellolar], T2.[E_MailL], T2.[BirthDate] FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
    Can you help me ?
    Jos Dielemans - Maastricht
    Edited by: J. Dielemans on Apr 29, 2011 4:28 PM
    Changed the query with Left Outer Join

    I have found the solution myself:
    By using the Union All function I could combine two queries. Here is the result:
    SELECT
    T0.[CardCode], T0.[CardName], T1.[Address] , T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_OpenTijd] , T1.[U_LosIns_1] , T1.[U_LosIns_2]'
    FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode
    WHERE T0.[CardCode] >= 'D00000'
    Union all
    SELECT
    T0.[CardCode], T0.[CardName], T2.[Position], T2.[Tel1], T2.[Title],  T2.[Name], T2.[Address], T2.[Position], T2.[Tel1], T2.[Cellolar], T2.[E_MailL]
    FROM OCRD T0 LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
    WHERE T0.[CardCode] >= 'D00000'
    Order by 1
    Now i got the result I was looking for.

  • Is that important column order in a query with row_number function

    Hi folks,
    I am using Oracle 11g R2 on HP-UX machine.
    I have 2 types of query with row_number and I think they are same but output of each of them are different. I changed only column order in query2.
    Query 1 :
    (SELECT
    "LOOKUP_INPUT_SUBQUERY"."CONTRACT_SK" "CONTRACT_SK",
    "LOOKUP_INPUT_SUBQUERY"."SIMCARD_SK" "SIMCARD_SK"
    FROM (
    SELECT row_number ()
    OVER (
    PARTITION BY "R_CON_SUBS_SIMCARD_LK".
    "CONTRACT_SK"
    ORDER BY
    "R_CON_SUBS_SIMCARD_LK"."START_DATE" DESC,
    "R_CON_SUBS_SIMCARD_LK"."SEQ_NUM" DESC NULLS LAST) /* EXPRESSION_3.OUTGRP1.SIRA */
    "SIRA",
    "R_CON_SUBS_SIMCARD_LK"."CONTRACT_SK" "CONTRACT_SK",
    "R_CON_SUBS_SIMCARD_LK"."SIMCARD_SK" "SIMCARD_SK"
    FROM "SRC_OZRDS"."R_CON_SUBS_SIMCARD_LK" "R_CON_SUBS_SIMCARD_LK")
    "LOOKUP_INPUT_SUBQUERY"
    WHERE ("LOOKUP_INPUT_SUBQUERY"."SIRA" = 1))
    Output of this like that :
    CONTRACT_SK SIMCARD_SK
    1     1
    1     3
    1     4
    1     5
    1     6
    1     11
    1     12
    1     14
    1     15
    1     16
    Query 2 :
    (SELECT
    "LOOKUP_INPUT_SUBQUERY"."CONTRACT_SK" "CONTRACT_SK",
    "LOOKUP_INPUT_SUBQUERY"."SIMCARD_SK" "SIMCARD_SK"
    FROM (
    SELECT
    "R_CON_SUBS_SIMCARD_LK"."CONTRACT_SK" "CONTRACT_SK",
    "R_CON_SUBS_SIMCARD_LK"."SIMCARD_SK" "SIMCARD_SK",
    row_number ()
    OVER (
    PARTITION BY "R_CON_SUBS_SIMCARD_LK".
    "CONTRACT_SK"
    ORDER BY
    "R_CON_SUBS_SIMCARD_LK"."START_DATE" DESC,
    "R_CON_SUBS_SIMCARD_LK"."SEQ_NUM" DESC NULLS LAST) /* EXPRESSION_3.OUTGRP1.SIRA */
    "SIRA"
    FROM "SRC_OZRDS"."R_CON_SUBS_SIMCARD_LK" "R_CON_SUBS_SIMCARD_LK")
    "LOOKUP_INPUT_SUBQUERY"
    WHERE ("LOOKUP_INPUT_SUBQUERY"."SIRA" = 1))
    Output of this like that:
    2     874812
    7     70097256
    8     18734091
    9     158024
    10     815397739
    13     22657919
    19     83177779
    20     82579529
    22     5829949
    23     35348926
    25     3865978
    I expected the second output, because there are lots of contract sk but there is one contract_sk in first query result. i did not get the point. What is the problem ?

    user8649469 wrote:
    I changed only column order in query2.So what else do you expect? If you order, for example, by last name, fist name don't you think rows will be returned in a different order (and therefore same row will have different row number) than ordering by first name, last name?
    SY.

  • Update of a table from a select query with aggregate functions.

    Hello All,
    I have problem here:
    I have 2 tables A(a1, a2, a3, a4, a4....... ) and B( a1, a2, b1, b2, b3). I need to calculate the avg(a4-a3), Max(a4-a3) and Min(a4-a3) and insert it into table B. If the foreign keys a1, a2 already exist in table B, I need to do an update of the computed values into column b1, b2 and b3 respectively, for a1, a2.
    Q1. Is it possible to do this with a single query ? I would prefer not to join A with B because the table A is very large. Also columns b1, b2 and b3 are non-nullable.
    Q2. Also if a4 and a3 are timestamps what is the best way to find the average? A difference of timestamps yields INTERVAL DAY TO SECOND over which the avg function doesn't seem to work. The averages, max and min in my case would be less than a day and hence all I need is to get the data in the hh:mm:ss format.
    As of now I'm using :
    TO_CHAR(TO_DATE(ABS(MOD(TRUNC(AVG(extract(hour FROM (last_modified_date - created_date))*3600 +
    extract( minute FROM (last_modified_date - created_date))*60 +
    extract( second FROM (last_modified_date - created_date)))
    ),86400)),'sssss'),'hh24":"mi":"ss') AS avg_time,
    But this is very long drawn. Something more compact and efficient would be nice.
    Thanks in advance for your inputs.
    Edited by: 847764 on Mar 27, 2011 5:35 PM

    847764 wrote:
    Hi,
    Thanks everyone for such fast replies. Malakshinov's example worked fine for me as far as updating the table goes. As for the timestamp computations, I'm posting additional info: Sorry, I don't understand.
    If Malakshinov's example worked for updating the table, but you still have problems, does that mean you have to do something else besides update the table? If so, what?
    Oracle version : Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
    Here are the table details :
    DESC Table A
    Name Null Type
    ID               NOT NULL NUMBER
    A1               NOT NULL VARCHAR2(4)
    A2               NOT NULL VARCHAR2(40)
    A3               NOT NULL VARCHAR2(40)
    CREATED_DATE NOT NULL TIMESTAMP(6)
    LAST_MODIFIED_DATE TIMESTAMP(6) DESCribing the tables can help clarify some things, but it's no substitute for posting CREATE TABLE and INSERT statements. With only a description of the table, nobody can re-create the problem or test their ideas. Please post CREATE TABLE and INSERT statements for both tables as they exist before the MERGE. If table b doen't contain any rows before the MERGE, then just say so, but you still need to post a CREATE TABLE statement for both tables, and INSERT statements for table a.
    The objective is to compute the response times : avg (LAST_MODIFIED_DATE - CREATED_DATE), max (LAST_MODIFIED_DATE - CREATED_DATE) and min (LAST_MODIFIED_DATE - CREATED_DATE) grouped by A1 and A2 and store it in table B under AVG_T, MAX_T and MIN_T. Since AVG_T, MAX_T and MIN_T are only used for reporting purposes we have kept it as Varchar (though I think keeping it as timestamp would make more sense). I think a NUMBER would make more sense (the number of minutes, for example), or perhaps an INTERVAL DAY TO SECOND. If you stored a NUMBER, it would be easy to compute averages.
    In table B the times are stored in the format : hh:mm:ss. We don't need milliseconds precision. If you don;'t need milliseconds, then you should use DATE instead of TIMESTAMP. The functions for manipulating DATEs are much better.
    Hence I was calculating is as follows:
    -- Avg Time
    TO_CHAR(TO_DATE(ABS(MOD(TRUNC(AVG(extract(hour FROM (last_modified_date - created_date))*3600 +
    extract( minute FROM (last_modified_date - created_date))*60 +
    extract( second FROM (last_modified_date - created_date)))
    ),86400)),'sssss'),'hh24":"mi":"ss') AS avg_time,
    --Max Time
    extract (hour FROM MAX(last_modified_date - created_date))||':'||extract (minute FROM MAX(last_modified_date - created_date))||':'||TRUNC(extract (second FROM MAX(last_modified_date - created_date))) AS max_time,
    --Min Time
    extract (hour FROM MIN(last_modified_date - created_date))||':'||extract (minute FROM MIN(last_modified_date - created_date))||':'||TRUNC(extract (second FROM MIN(last_modified_date - created_date))) AS min_timeIs this something that has to be done before or after the MERGE?
    Post the complete statement.
    Is this part of a query? Where's the SELECT keyword?
    Is this part of a DML operation? Where's the INSERT, or UPDATE, or MERGE keyword?
    What are the exact results you want from this? Explain how you get those results.
    Is the code above getting the right results? Are you just asking if there's a better way to get the same results?
    You have to explain things very carefully. None of the people who want to help you are familiar with your application, or your needs.
    I just noticed that my reply is horribly formatted - apologies! I'm just getting the hang of it.Whenever you post formatted text (such as query results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • SQL query with object function

    I want to write a function, which returns more than one value and to include those values into a SQL statement. For example I want to query the RDB with....
    select t.id, my_function(t.id).value1 name, my_function(t.id).value2 address ....
    from table_x t
    where t.id between 1 and 10
    and bitand(my_function(t,id)).sec_id,2)>3
    Is it possible to do something like this?
    I tried to use object and table of objects(my_type) to return value of my_type but when I used
    select ......my_function(t.id).name,my_function(t.id).address ...
    from table_x
    where t.id=some_value;
    the function was called twice(i expected this result, but i don't know how to avoid it).
    Simple example
    CREATE OR REPLACE TYPE l_test AS OBJECT
    id NUMBER(10),
    name varchar2(100),
    a_date date
    CREATE OR REPLACE FUNCTION test_f2(test_number IN NUMBER)
    RETURN l_test
    IS
    a number;
    BEGIN
    select t_seq.nextval into a from dual;
    return l_test(a,'test value ='||test_number,sysdate+test_number);
    END;
    select test_f2(i.id).id client_id, test_f2(i.id).name client_name from r_owners i
    CLIENT_ID CLIENT_NAME
    1 test value =1
    3 test value =2
    I want to be able to loop in cursor and use those values
    All ideas are welcome!
    Thanks,
    Iassen Houbenov

    Check it out...
    SQL> CREATE OR REPLACE TYPE emp_add AS OBJECT
      2  (  office VARCHAR2(50),
      3     location VARCHAR2(50),
      4      MEMBER FUNCTION get_office RETURN VARCHAR2,
      5      MEMBER FUNCTION get_location RETURN VARCHAR2,
      6      CONSTRUCTOR FUNCTION emp_add(id NUMBER) RETURN SELF AS RESULT,
      7      CONSTRUCTOR FUNCTION emp_add(id NUMBER, office VARCHAR2,location VARCHAR2) RETURN
      8        SELF AS RESULT
      9  ) NOT FINAL;
    10  /
    Type created.
    SQL> CREATE OR REPLACE TYPE BODY emp_add IS
      2      MEMBER FUNCTION get_office RETURN VARCHAR2
      3      IS
      4      BEGIN
      5          RETURN SELF.office;
      6      END;
      7      MEMBER FUNCTION get_location RETURN VARCHAR2
      8      IS
      9      BEGIN
    10          RETURN SELF.location;
    11      END;
    12      CONSTRUCTOR FUNCTION emp_add(id NUMBER)
    13          RETURN SELF AS RESULT
    14      IS
    15      BEGIN
    16         SELECT dname, loc
    17         INTO   SELF.office, SELF.location
    18         FROM   dept
    19         WHERE  deptno = id;
    20         RETURN;
    21      END;
    22      CONSTRUCTOR FUNCTION emp_add(id NUMBER, office VARCHAR2,location VARCHAR2)
    23          RETURN SELF AS RESULT
    24      IS
    25      BEGIN
    26         SELF.office := office;
    27         SELF.location := location;
    28         RETURN;
    29      END;
    30  END;
    31  /
    Type body created.
    SQL> SELECT e.ename, e.d.office, e.d.location 
      2  FROM   ( SELECT ename
      3                 , (SELECT emp_add(emp.deptno) FROM dual ) d
      4           FROM   emp ) e
      5  /
    ENAME      D.OFFICE
    D.LOCATION
    SMITH      RESEARCH
    DALLAS
    ALLEN      SALES
    CHICAGO
    WARD       SALES
    CHICAGO
    ....Smoke me a kipper I'll be back before breakfast.
    Cheers, APC

  • Query with trim function running more than 15 hours..

    Hi,
    I have one select query which is running more than 15 hours.I have many trim() functions in that.and i have index for some columns for the tables that i used in that query.but it is not considering those indexes..
    select
    DISTINCT
    trim(A.x) x,
    trim(B.y) y,....... from A,B
    Can anyone tell why this query is taking more time?and is there any other way for using the trim function?
    Thanks in advance..

    Note the name of this forum is "SQL Developer *(Not for general SQL/PLSQL questions)*", so only for issues with the SQL Developer tool. Please post these questions under the dedicated [SQL And PL/SQL|https://forums.oracle.com/forums/forum.jspa?forumID=75] forum.
    Regards,
    K.

  • Speed up query with analytic function

    Hi
    how can I speed up the query below ?
    All time is in analytic function (WINDOW SORT)
    Thanks for your help
    11.2.0.1
    Rows     Row Source Operation
      28987  HASH UNIQUE (cr=12677 pr=155778 pw=109730 time=25010 us cost=5502 size=3972960 card=14880)
    1668196   WINDOW SORT (cr=12677 pr=155778 pw=109730 time=890411840 us cost=5502 size=3972960 card=14880)
    1668196    HASH JOIN RIGHT OUTER (cr=12677 pr=0 pw=0 time=1069165 us cost=3787 size=3972960 card=14880)
      30706     TABLE ACCESS FULL FLO_FML_EVENT (cr=270 pr=0 pw=0 time=7420 us cost=56 size=814158 card=30154)
    194733     HASH JOIN RIGHT OUTER (cr=12407 pr=0 pw=0 time=571145 us cost=3730 size=3571200 card=14880)
        613      VIEW  (cr=342 pr=0 pw=0 time=489 us cost=71 size=23840 card=745)
        613       HASH UNIQUE (cr=342 pr=0 pw=0 time=244 us cost=71 size=20115 card=745)
        745        WINDOW SORT (cr=342 pr=0 pw=0 time=1736 us cost=71 size=20115 card=745)
        745         MAT_VIEW ACCESS FULL MVECRF_CUR_QUERY (cr=342 pr=0 pw=0 time=1736 us cost=69 size=20115 card=745)
    194733      HASH JOIN  (cr=12065 pr=0 pw=0 time=431813 us cost=3658 size=3095040 card=14880)
         43       MAT_VIEW ACCESS FULL MVECRF_VISIT_REVS (cr=3 pr=0 pw=0 time=0 us cost=2 size=946 card=43)
    194733       HASH JOIN OUTER (cr=12062 pr=0 pw=0 time=292098 us cost=3656 size=2767680 card=14880)
    194733        HASH JOIN OUTER (cr=10553 pr=0 pw=0 time=234394 us cost=2962 size=2574240 card=14880)
    194733         HASH JOIN  (cr=9999 pr=0 pw=0 time=379996 us cost=2570 size=2380800 card=14880)
      30076          MAT_VIEW ACCESS FULL MVECRF_ACTIVATED_FORMS (cr=1817 pr=0 pw=0 time=28411 us cost=361 size=2000285 card=29855)
    194733          HASH JOIN  (cr=8182 pr=0 pw=0 time=209061 us cost=1613 size=9026301 card=97057)
        628           MAT_VIEW ACCESS FULL MVECRF_STUDYVERSION_FORMS (cr=19 pr=0 pw=0 time=250 us cost=6 size=18212 card=628)
    194733           MAT_VIEW ACCESS FULL MVECRF_FORMITEMS (cr=8163 pr=0 pw=0 time=80733 us cost=1606 size=12462912 card=194733)
    132342         MAT_VIEW ACCESS FULL MVECRF_ITEM_SDV (cr=554 pr=0 pw=0 time=23678 us cost=112 size=1720446 card=132342)
    221034        MAT_VIEW ACCESS FULL MVECRF_ITEMDATA (cr=1509 pr=0 pw=0 time=46459 us cost=299 size=2873442 card=221034)
    SELECT              
          DISTINCT
             'CL238093011' AS ETUDE,
             FI.STUDYID,
             FI.STUDYVERSIONID,
             FI.SITEID,
             FI.SUBJECTID,
             FI.VISITID,
             VR.VISITREFNAME,
             FI.SUBJECTVISITID,
             FI.FORMID,
             FI.FORMINDEX,
             SVF.FORMREFNAME,
             SVF.FORMMNEMONIC AS FMLNOM,
             EVENT_ITEM.EVENT AS EVENUM,
             EVENT_ITEM.EVENT_ROW AS LIGNUM,
             NULL AS CODVISEVE,
             MIN(DID.MINENTEREDDATE)
                OVER (
                   PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
                AS ATTDAT1ERSAI,
             MIN(IFSDV.ITEMFIRSTSDV)
                OVER (
                   PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
                AS ATTDAT1ERSDV,
             MAX(IFSDV.ITEMFIRSTSDV)
                OVER (
                   PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
                AS ATTDATDERSDV,
             DECODE (AF.SDVCOMPLETESTATE,
                     0,
                     'N',
                     1,
                     'Y')
                AS ATTINDSDVCOP,
             AF.FMINSDVCOMPLETESTATE AS ATTDAT1ERSDVCOP,
             DECODE (AF.SDVPARTIALSTATE,
                     0,
                     'N',
                     1,
                     'Y')
                AS ATTINDSDVPTL,
             EVENT_ITEM.EVENT_RELECT AS ATTINDRVUMEDCOP,
             DECODE (QUERY.NBQSTFML, NULL, 'N', 'Y') AS ATTINDQST,
             DECODE (AF.MISSINGITEMSSTATE,
                     0,
                     'N',
                     1,
                     'Y')
                AS ATTINDITMABS,
             DECODE (AF.FROZENSTATE,
                     0,
                     'N',
                     1,
                     'Y')
                AS ATTINDETACON,
             AF.FMINFROZENSTATE AS ATTDAT1ERCON,
             AF.FMAXFROZENSTATE AS ATTDATDERCON,
             DECODE (AF.DELETEDSTATE,
                     0,
                     'N',
                     1,
                     'Y')
                AS ATTINDETASPR,
             EVENT_ITEM.ROW_DELETED AS ATTINDLIGSPR
      FROM   CL238093011.MVECRF_FORMITEMS FI,
             CL238093011.MVECRF_STUDYVERSION_FORMS SVF,
             CL238093011.MVECRF_ACTIVATED_FORMS AF,
             CL238093011.MVECRF_ITEM_SDV IFSDV,
             CL238093011.MVECRF_VISIT_REVS VR,
             CL238093011.MVECRF_ITEMDATA DID,
             (SELECT   DISTINCT
                       SUBJECTID,
                       VISITID,
                       FORMID,
                       FORMINDEX,
                       COUNT (
                          DISTINCT QUERYID
                          OVER (
                             PARTITION BY SUBJECTID, VISITID, FORMID, FORMINDEX
                          NBQSTFML
                FROM   CL238093011.MVECRF_CUR_QUERY
               WHERE   QUERYSTATE IN (0, 1, 2)) QUERY,
             CL238093011.FLO_FML_EVENT EVENT_ITEM
    WHERE   (AF.VISITDELETED IS NULL OR AF.VISITDELETED = 0)
             AND AF.FORMTYPE NOT IN (4, 5, 6, 7, 8, 103)
             AND (AF.DELETEDDYNAMICFORMSTATE IS NULL
                  OR AF.DELETEDDYNAMICFORMSTATE = 0)
             AND FI.SUBJECTVISITID = AF.SUBJECTVISITID
             AND FI.FORMID = AF.FORMID
             AND FI.FORMREV = AF.FORMREV
             AND FI.FORMINDEX = AF.FORMINDEX
             AND FI.VISITID = VR.VISITID
             AND FI.VISITREV = VR.VISITREV
             AND FI.CONTEXTID = IFSDV.CONTEXTID(+)
             AND FI.CONTEXTID = DID.CONTEXTID(+)
             AND FI.SUBJECTID = QUERY.SUBJECTID(+)
             AND FI.VISITID = QUERY.VISITID(+)
             AND FI.FORMID = QUERY.FORMID(+)
             AND FI.FORMINDEX = QUERY.FORMINDEX(+)
             AND FI.STUDYVERSIONID = SVF.STUDYVERSIONID
             AND FI.FORMID = SVF.FORMID
             AND FI.VISITID = SVF.VISITID
             AND FI.SUBJECTID = EVENT_ITEM.SUBJECTID(+)
             AND FI.VISITID = EVENT_ITEM.VISITID(+)
             AND FI.FORMID = EVENT_ITEM.FORMID(+)
             AND FI.FORMINDEX = EVENT_ITEM.FORMINDEX(+)

    user12045475 wrote:
    Hi
    how can I speed up the query below ?
    All time is in analytic function (WINDOW SORT)
    Thanks for your help
    11.2.0.1
    Rows     Row Source Operation
    28987  HASH UNIQUE (cr=12677 pr=155778 pw=109730 time=25010 us cost=5502 size=3972960 card=14880)
    1668196   WINDOW SORT (cr=12677 pr=155778 pw=109730 time=890411840 us cost=5502 size=3972960 card=14880)
    1668196    HASH JOIN RIGHT OUTER (cr=12677 pr=0 pw=0 time=1069165 us cost=3787 size=3972960 card=14880)
    30706     TABLE ACCESS FULL FLO_FML_EVENT (cr=270 pr=0 pw=0 time=7420 us cost=56 size=814158 card=30154)
    194733     HASH JOIN RIGHT OUTER (cr=12407 pr=0 pw=0 time=571145 us cost=3730 size=3571200 card=14880)
    613      VIEW  (cr=342 pr=0 pw=0 time=489 us cost=71 size=23840 card=745)
    613       HASH UNIQUE (cr=342 pr=0 pw=0 time=244 us cost=71 size=20115 card=745)
    745        WINDOW SORT (cr=342 pr=0 pw=0 time=1736 us cost=71 size=20115 card=745)
    745         MAT_VIEW ACCESS FULL MVECRF_CUR_QUERY (cr=342 pr=0 pw=0 time=1736 us cost=69 size=20115 card=745)
    194733      HASH JOIN  (cr=12065 pr=0 pw=0 time=431813 us cost=3658 size=3095040 card=14880)
    43       MAT_VIEW ACCESS FULL MVECRF_VISIT_REVS (cr=3 pr=0 pw=0 time=0 us cost=2 size=946 card=43)
    194733       HASH JOIN OUTER (cr=12062 pr=0 pw=0 time=292098 us cost=3656 size=2767680 card=14880)
    194733        HASH JOIN OUTER (cr=10553 pr=0 pw=0 time=234394 us cost=2962 size=2574240 card=14880)
    194733         HASH JOIN  (cr=9999 pr=0 pw=0 time=379996 us cost=2570 size=2380800 card=14880)
    30076          MAT_VIEW ACCESS FULL MVECRF_ACTIVATED_FORMS (cr=1817 pr=0 pw=0 time=28411 us cost=361 size=2000285 card=29855)
    194733          HASH JOIN  (cr=8182 pr=0 pw=0 time=209061 us cost=1613 size=9026301 card=97057)
    628           MAT_VIEW ACCESS FULL MVECRF_STUDYVERSION_FORMS (cr=19 pr=0 pw=0 time=250 us cost=6 size=18212 card=628)
    194733           MAT_VIEW ACCESS FULL MVECRF_FORMITEMS (cr=8163 pr=0 pw=0 time=80733 us cost=1606 size=12462912 card=194733)
    132342         MAT_VIEW ACCESS FULL MVECRF_ITEM_SDV (cr=554 pr=0 pw=0 time=23678 us cost=112 size=1720446 card=132342)
    221034        MAT_VIEW ACCESS FULL MVECRF_ITEMDATA (cr=1509 pr=0 pw=0 time=46459 us cost=299 size=2873442 card=221034)
    SELECT              
    DISTINCT
    'CL238093011' AS ETUDE,
    FI.STUDYID,
    FI.STUDYVERSIONID,
    FI.SITEID,
    FI.SUBJECTID,
    FI.VISITID,
    VR.VISITREFNAME,
    FI.SUBJECTVISITID,
    FI.FORMID,
    FI.FORMINDEX,
    SVF.FORMREFNAME,
    SVF.FORMMNEMONIC AS FMLNOM,
    EVENT_ITEM.EVENT AS EVENUM,
    EVENT_ITEM.EVENT_ROW AS LIGNUM,
    NULL AS CODVISEVE,
    MIN(DID.MINENTEREDDATE)
    OVER (
    PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
    AS ATTDAT1ERSAI,
    MIN(IFSDV.ITEMFIRSTSDV)
    OVER (
    PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
    AS ATTDAT1ERSDV,
    MAX(IFSDV.ITEMFIRSTSDV)
    OVER (
    PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
    AS ATTDATDERSDV,
    DECODE (AF.SDVCOMPLETESTATE,
    0,
    'N',
    1,
    'Y')
    AS ATTINDSDVCOP,
    AF.FMINSDVCOMPLETESTATE AS ATTDAT1ERSDVCOP,
    DECODE (AF.SDVPARTIALSTATE,
    0,
    'N',
    1,
    'Y')
    AS ATTINDSDVPTL,
    EVENT_ITEM.EVENT_RELECT AS ATTINDRVUMEDCOP,
    DECODE (QUERY.NBQSTFML, NULL, 'N', 'Y') AS ATTINDQST,
    DECODE (AF.MISSINGITEMSSTATE,
    0,
    'N',
    1,
    'Y')
    AS ATTINDITMABS,
    DECODE (AF.FROZENSTATE,
    0,
    'N',
    1,
    'Y')
    AS ATTINDETACON,
    AF.FMINFROZENSTATE AS ATTDAT1ERCON,
    AF.FMAXFROZENSTATE AS ATTDATDERCON,
    DECODE (AF.DELETEDSTATE,
    0,
    'N',
    1,
    'Y')
    AS ATTINDETASPR,
    EVENT_ITEM.ROW_DELETED AS ATTINDLIGSPR
    FROM   CL238093011.MVECRF_FORMITEMS FI,
    CL238093011.MVECRF_STUDYVERSION_FORMS SVF,
    CL238093011.MVECRF_ACTIVATED_FORMS AF,
    CL238093011.MVECRF_ITEM_SDV IFSDV,
    CL238093011.MVECRF_VISIT_REVS VR,
    CL238093011.MVECRF_ITEMDATA DID,
    (SELECT   DISTINCT
    SUBJECTID,
    VISITID,
    FORMID,
    FORMINDEX,
    COUNT (
    DISTINCT QUERYID
    OVER (
    PARTITION BY SUBJECTID, VISITID, FORMID, FORMINDEX
    NBQSTFML
    FROM   CL238093011.MVECRF_CUR_QUERY
    WHERE   QUERYSTATE IN (0, 1, 2)) QUERY,
    CL238093011.FLO_FML_EVENT EVENT_ITEM
    WHERE   (AF.VISITDELETED IS NULL OR AF.VISITDELETED = 0)
    AND AF.FORMTYPE NOT IN (4, 5, 6, 7, 8, 103)
    AND (AF.DELETEDDYNAMICFORMSTATE IS NULL
    OR AF.DELETEDDYNAMICFORMSTATE = 0)
    AND FI.SUBJECTVISITID = AF.SUBJECTVISITID
    AND FI.FORMID = AF.FORMID
    AND FI.FORMREV = AF.FORMREV
    AND FI.FORMINDEX = AF.FORMINDEX
    AND FI.VISITID = VR.VISITID
    AND FI.VISITREV = VR.VISITREV
    AND FI.CONTEXTID = IFSDV.CONTEXTID(+)
    AND FI.CONTEXTID = DID.CONTEXTID(+)
    AND FI.SUBJECTID = QUERY.SUBJECTID(+)
    AND FI.VISITID = QUERY.VISITID(+)
    AND FI.FORMID = QUERY.FORMID(+)
    AND FI.FORMINDEX = QUERY.FORMINDEX(+)
    AND FI.STUDYVERSIONID = SVF.STUDYVERSIONID
    AND FI.FORMID = SVF.FORMID
    AND FI.VISITID = SVF.VISITID
    AND FI.SUBJECTID = EVENT_ITEM.SUBJECTID(+)
    AND FI.VISITID = EVENT_ITEM.VISITID(+)
    AND FI.FORMID = EVENT_ITEM.FORMID(+)
    AND FI.FORMINDEX = EVENT_ITEM.FORMINDEX(+)
    Do you have the license for parallel query (may/may not help)? PQO can help with sorts ...

  • Creating a  query with group function and non group function

    Could anyone help me with creating a query that contain single row function and multiple row function in Report6i.
    what i want to do basically is to create a query that will display sum of certain columns according to a column in that table

    You can either calculate a sum yourself, or let Reports do it for you.
    1. select sum(column) from table where ....
    This will just display the sum, not the records.
    2. Make a query: select column from table where ...
    Create a summary field. You can do it manually or with the report wizard.
    That will create a report like this:
       Column
           10
           20
           15
       ======
    Sum    45                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Select Query with Sub

    The following query gives me a syntax error using Access 2013
    SELECT a.DATEa, c.TotalHours
    from tblEightToNine a
    where a.DATEa  EXISTS IN
      (SELECT b.Datea,Count(b.AGENT) as TotalHours
       From tblEightToNine b
       where a.DATEa = b.DATEa)
    GROUP BY a.DATEa
    Syntax error in query expression a.DATEA Exists IN (Select b.Datea, Count(b.AGENT) as TotalHours From tblEightToNine b where a.DATEa = b.DATEA)

    Hi,
    Please try Maurice's suggestion first, and see the article about the SELECT Statement of Access SQL syntax.
    http://msdn.microsoft.com/en-us/library/office/ff821148(v=office.15).aspx
    If you have further question about the Access SQL, please post your question to the MSDN forum for Access
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=accessdev&filter=alltypes&sort=lastpostdesc
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Af:query with extra functionality

    Hello everyone,
    JDev: 11.1.1.3 (migrating to 11.1.1.5)
    We are using the af:query component as our standard query module (seems logical).
    Thanks to the Frank Nimphius "af:query component complex field validation" on the ADF Code Corner,
    it is clear how to do validation in an af:query component.
    What we want to do is the following : on an existing field, adding a link/icon that opens a popup that contains
    a taskflow, which contains a more complex query (again with af:query ;-)). The result of the tf should return
    into the field in the first af:query component.
    Is something like this possible?
    Thanks.
    Filip Huysmans.

    Filip,
    no, you can't
    Frank

  • Query with DECODE function

    My table has columns A,B & C with data as below
    A B C
    X 1 1
    1 X 1
    1 1 X
    Result should be all ‘Z’ inserted right to ‘X’ & must look like as below
    A B C
    X Z Z
    1 X Z
    1 1 X
    Please check the below query & help me to modify the query as the result for column b is not correct.
    select a,decode(b,'1','Z','X') b,decode(c,'1','Z','X') c
    from test;

    try
    With Data As
    Select 'X' A,'1' B, '1' C From Dual Union All
    Select '1','X','1' From Dual Union All
    Select '1','1','X' From Dual
    Select A, (Case When A ='X' And B='1' Then 'Z' Else B End) B,
    (Case When (A='X' Or B='X') And C='1' Then 'Z' Else C end)C 
    from dataVivek L

  • Help with query with sub query

    hi
    I am trying to run the following query and it returns an error as follows:
    ORA 00904: ST_ENROLLMENT.absence_reason_code: invalid SQL identfiier.
    the code is as follows:
    SELECT
            ST_ENROLLMENT.student_id,
            last_name,
            first_name,
            date_of_birth,
            grade_level AS grade,
            gender AS GnDr,
            home_phone_number,
            absence_reason_code
            FROM ST_ENROLLMENT,CE_FAMILY_MEMBER, CE_FAMILY, AT_HOURLY_ATTENDANCE_RECORDS,
           (SELECT
                        COUNT(attendance_status) AS "ConsecutiveDaysAbsent"
                        FROM AT_HOURLY_ATTENDANCE_RECORDS, ST_ENROLLMENT
                     WHERE AT_HOURLY_ATTENDANCE_RECORDS.student_id = ST_ENROLLMENT.student_id
           AND  AT_HOURLY_ATTENDANCE_RECORDS.school_id = ST_ENROLLMENT.school_id
           AND AT_HOURLY_ATTENDANCE_RECORDS.school_year = ST_ENROLLMENT.school_year
           AND ST_ENROLLMENT.district_number = AT_HOURLY_ATTENDANCE_RECORDS.district_number
           AND AT_HOURLY_ATTENDANCE_RECORDS.track_number = ST_ENROLLMENT.track_number
           AND AT_HOURLY_ATTENDANCE_RECORDS.absence_reason_code = ST_ENROLLMENT.absence_reason_code
           AND AT_HOURLY_ATTENDANCE_RECORDS.student_id = ST_ENROLLMENT.student_id); thanks in advance. I appreciate everybody for their help

    To avoid a cartesian product, you need to join the tables which are into the from clause. For this, you need to know the column which must be joined.
    If I take, for example, some tables from the very know basic schema scott, and I would like the name of emp and the name of dept for each emp, I will join emp table dept table on a common column.
    SCOTT@demo102> desc emp
    Name                                      Null?    Type
    EMPNO                                     NOT NULL NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO NUMBER(2)
    SCOTT@demo102> desc dept
    Name                                      Null?    Type
    DEPTNO NOT NULL NUMBER(2)
    DNAME                                              VARCHAR2(14)
    LOC                                                VARCHAR2(13)
    SCOTT@demo102> select emp.ename, dept.dname
      2  from emp, dept
      3  where emp.deptno=dept.deptno;
    ENAME      DNAME
    CLARK      ACCOUNTING
    KING       ACCOUNTING
    MILLER     ACCOUNTING
    JONES      RESEARCH
    FORD       RESEARCH
    ADAMS      RESEARCH
    SMITH      RESEARCH
    SCOTT      RESEARCH
    WARD       SALES
    TURNER     SALES
    ALLEN      SALES
    ENAME      DNAME
    JAMES      SALES
    BLAKE      SALES
    MARTIN     SALES
    14 rows selected.
    SCOTT@demo102> HTH,
    Nicolas.

  • Need valuable guidance to make a peformance oriented query, trying to replace unions with analytical function

    Hi,
       Please find below table structure and insert scritps. Requesting for vluable help.
    create table temp2 (col1 number,col2 varchar2(10),col3 number,col4 varchar2(20));
    insert into temp2 values (1,'a',100,'vvv');
    insert into temp2 values (2,'b',200,'www'); 
    insert into temp2 values (3,'c',300,'xxx');
    insert into temp2 values (4,'d',400,'yyy');   
    insert into temp2 values (5,'e',500,'zzz');
    insert into temp2 values (6,'f',600,'aaa');
    insert into temp2 values (7,'g',700,'bbb'); 
    insert into temp2 values (8,'h',800,'ccc');
    I am trying to get same output, what we get from below UNION query with ANALYTICAL Function.
    select * from temp2 where col1 in (1,2,3,4,5)
    union
    select * from temp2 where col1 in (1,2,5,6)
    union
    select * from temp2 where col1 in (1,2,7,8);
    I am seeking help by this dummy example to understand the concept, how can we use analytical functional over UNION or OUTER JOINS.
    In my exact query, I am using same table three times adding UNION clause. here also we scan temp2 three times, so for bulky tables using 'union'  would be hampering query's performance
    It means i go with three time scans of same table that is not performance oriented. With the help of above required concept, i will try to remove UNIONs from my exact query.
    Thanks!!

    Thanks for your time BluShadow and sorry as i think i couldn't make my query clear.
    I try it again. Below there are three queries, you may see all three queries are using same tables. Difference in all three queries are just few conditions, which makes all three queries diff with each other.
    I know, u cant run below query in your database, but i think it will convey my doubt to you. I have mentioned no. of rows with each clause and total i am getting 67 rows as my output. (Reason may be first n third query's result set are the subset of Second Query dataset)
    So i want to take all common rows as well as additional rows, if present in any of the query. This is getting easliy done with UNION clause but want to have it in other way as here my same is getting scanned again n again.
    SELECT
             START_TX.FX_TRAN_ID START_FX_TRAN_ID
            ,END_TX.FX_TRAN_ID END_FX_TRAN_ID
            ,START_TX.ENTERED_DT_TS
            ,USER
            ,START_TX.TRADE_DT
            ,START_TX.DEAL_NUMBER
            ,START_TX.FX_DEAL_TYPE
            ,START_TX.ORIENTATION_BUYSELL
            ,START_TX.BASE_CCY
            ,START_TX.BASE_CCY_AMT
            ,START_TX.SECONDARY_CCY
            ,START_TX.SECONDARY_CCY_AMT
            ,START_TX.MATURITY_DT
            ,START_TX.TRADE_RT
            ,START_TX.FORWARD_PTS              
            ,START_TX.CORPORATE_PIPS           
            ,START_TX.DEAL_OWNER_INITIALS      
            ,START_TX.CORPORATE_DEALER         
            ,START_TX.PROFIT_CENTER_CD
            ,START_TX.COUNTERPARTY_NM
            ,START_TX.COUNTERPARTY_NUMBER
      FROM
          (SELECT * FROM FX_TRANSACTIONS WHERE GMT_CONV_ENTERED_DT_TS >=  TO_DATE('20-Nov-2013 4:00:01 AM','DD-Mon-YYYY HH:MI:SS AM')) START_TX
           INNER JOIN
          (SELECT * FROM FX_TRANSACTIONS WHERE GMT_CONV_ENTERED_DT_TS <=  TO_DATE('20-Nov-2013 4:59:59 PM','DD-Mon-YYYY HH:MI:SS AM'))  END_TX
       ON START_TX.COUNTERPARTY_NM        = END_TX.COUNTERPARTY_NM         AND
          START_TX.COUNTERPARTY_NUMBER    = END_TX.COUNTERPARTY_NUMBER     AND
          START_TX.FX_DEAL_TYPE           = END_TX.FX_DEAL_TYPE            AND
          START_TX.BASE_CCY               = END_TX.BASE_CCY                AND
          START_TX.SECONDARY_CCY          = END_TX.SECONDARY_CCY           AND
          NVL(START_TX.CORPORATE_DEALER,'nullX')=NVL(END_TX.CORPORATE_DEALER,'nullX')       AND
          START_TX.ORIENTATION_BUYSELL='B'                                 AND 
          END_TX.ORIENTATION_BUYSELL='S'                                  AND
          START_TX.FX_TRAN_ID = 1850718                                  AND
         (START_TX.BASE_CCY_AMT           = END_TX.BASE_CCY_AMT          
          OR
          START_TX.SECONDARY_CCY_AMT      = END_TX.SECONDARY_CCY_AMT)        -- 10 Rows
    UNION
    SELECT
             START_TX.FX_TRAN_ID START_FX_TRAN_ID
            ,END_TX.FX_TRAN_ID END_FX_TRAN_ID
            ,START_TX.ENTERED_DT_TS
            ,USER
            ,START_TX.TRADE_DT
            ,START_TX.DEAL_NUMBER
            ,START_TX.FX_DEAL_TYPE
            ,START_TX.ORIENTATION_BUYSELL
            ,START_TX.BASE_CCY
            ,START_TX.BASE_CCY_AMT
            ,START_TX.SECONDARY_CCY
            ,START_TX.SECONDARY_CCY_AMT
            ,START_TX.MATURITY_DT
            ,START_TX.TRADE_RT
            ,START_TX.FORWARD_PTS              
            ,START_TX.CORPORATE_PIPS           
            ,START_TX.DEAL_OWNER_INITIALS      
            ,START_TX.CORPORATE_DEALER         
            ,START_TX.PROFIT_CENTER_CD
            ,START_TX.COUNTERPARTY_NM
            ,START_TX.COUNTERPARTY_NUMBER
      FROM
          (SELECT * FROM FX_TRANSACTIONS WHERE GMT_CONV_ENTERED_DT_TS >=  TO_DATE('20-Nov-2013 4:00:01 AM','DD-Mon-YYYY HH:MI:SS AM')) START_TX
           INNER JOIN
          (SELECT * FROM FX_TRANSACTIONS WHERE GMT_CONV_ENTERED_DT_TS <=  TO_DATE('20-Nov-2013 4:59:59 PM','DD-Mon-YYYY HH:MI:SS AM'))  END_TX
       ON START_TX.COUNTERPARTY_NM        = END_TX.COUNTERPARTY_NM         AND
          START_TX.COUNTERPARTY_NUMBER    = END_TX.COUNTERPARTY_NUMBER     AND
          START_TX.FX_DEAL_TYPE           = END_TX.FX_DEAL_TYPE            AND
          START_TX.BASE_CCY               = END_TX.BASE_CCY                AND
          START_TX.SECONDARY_CCY          = END_TX.SECONDARY_CCY           AND
          NVL(START_TX.CORPORATE_DEALER,'nullX')=NVL(END_TX.CORPORATE_DEALER,'nullX')  AND
          START_TX.FX_TRAN_ID = 1850718                                  AND
          START_TX.ORIENTATION_BUYSELL='B'                                 AND 
          END_TX.ORIENTATION_BUYSELL='S'                        --                                   67 Rows
    UNION 
    SELECT
             START_TX.FX_TRAN_ID START_FX_TRAN_ID
            ,END_TX.FX_TRAN_ID END_FX_TRAN_ID
            ,START_TX.ENTERED_DT_TS
            ,USER
            ,START_TX.TRADE_DT
            ,START_TX.DEAL_NUMBER
            ,START_TX.FX_DEAL_TYPE
            ,START_TX.ORIENTATION_BUYSELL
            ,START_TX.BASE_CCY
            ,START_TX.BASE_CCY_AMT
            ,START_TX.SECONDARY_CCY
            ,START_TX.SECONDARY_CCY_AMT
            ,START_TX.MATURITY_DT
            ,START_TX.TRADE_RT
            ,START_TX.FORWARD_PTS              
            ,START_TX.CORPORATE_PIPS           
            ,START_TX.DEAL_OWNER_INITIALS      
            ,START_TX.CORPORATE_DEALER         
            ,START_TX.PROFIT_CENTER_CD
            ,START_TX.COUNTERPARTY_NM
            ,START_TX.COUNTERPARTY_NUMBER
      FROM
          (SELECT * FROM FX_TRANSACTIONS WHERE GMT_CONV_ENTERED_DT_TS >=  TO_DATE('20-Nov-2013 4:00:01 AM','DD-Mon-YYYY HH:MI:SS AM')) START_TX
           INNER JOIN
          (SELECT * FROM FX_TRANSACTIONS WHERE GMT_CONV_ENTERED_DT_TS <=  TO_DATE('20-Nov-2013 4:59:59 PM','DD-Mon-YYYY HH:MI:SS AM'))  END_TX
       ON START_TX.COUNTERPARTY_NM        = END_TX.COUNTERPARTY_NM         AND
          START_TX.COUNTERPARTY_NUMBER    = END_TX.COUNTERPARTY_NUMBER     AND
          START_TX.FX_DEAL_TYPE           = END_TX.FX_DEAL_TYPE            AND
          START_TX.BASE_CCY               = END_TX.BASE_CCY                AND
          START_TX.SECONDARY_CCY          = END_TX.SECONDARY_CCY           AND
          NVL(START_TX.CORPORATE_DEALER,'nullX')=NVL(END_TX.CORPORATE_DEALER,'nullX') AND
          START_TX.ORIENTATION_BUYSELL='B'                                 AND 
          END_TX.ORIENTATION_BUYSELL='S'                                   AND
          START_TX.FX_TRAN_ID = 1850718                                  AND
            END_TX.BASE_CCY_AMT BETWEEN (START_TX.BASE_CCY_AMT - (START_TX.BASE_CCY_AMT * :PERC_DEV/100)) AND (START_TX.BASE_CCY_AMT + (START_TX.BASE_CCY_AMT * :PERC_DEV/100))        
            OR
            END_TX.SECONDARY_CCY_AMT BETWEEN (START_TX.SECONDARY_CCY_AMT - (START_TX.SECONDARY_CCY_AMT*:PERC_DEV/100) ) AND (START_TX.SECONDARY_CCY_AMT + (START_TX.SECONDARY_CCY_AMT*:PERC_DEV/100))
        );                                                       ---                              10 Rows

Maybe you are looking for

  • How can I create a java.awt.Image from ...

    Hi all, How can I create a java.awt.Image from a drawing on a JPanel? Thanks.

  • Remaining moments/collections in the iOS 7 Photos app

    I just installed iOS 7 on my iPhone 4S and iPad mini. Does anyone know if there is a way to rename the "miments" or "collections" in the Photos app? I like how it's organized, but I wish that the album of pictures from my uncle's wedding could be nam

  • How to go wireless

    hi. here is a stupid question i just ordered the new imac, which comes with airport. currently i have a cable modem, so how i make this a wireless connection, using the airport that came with the new imac? thanks nikos

  • Server app, airport extreme

    I have a MacMini, running 10.9.x, and Server App 3.02. I have a airport Extreme, and it isn't showing in the server app like it is supposed to. The airport is providing the wireless network for my whole network. any ideas why or how I can add it into

  • Clips in timeline are between frames

    When i open premiere pro sometimes I'll find that the clips in my timeline are not on an actual frame but inbetween a frame and I can't seem to fix it. Any thoughts? Thank you