Oracle analytic function setting

Hi all
Oracle Database 10 g Enterprise Edition release 10.2.0.3.0 - 64bi
PL/SQL version 10.2.0.3.0 - Production
CORE Production 10.2.0.3.0
AMT for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - production
NLSRTL Version 10.2.0.3.0 - Production
I have a query that has analytic function uses space on temporary tablespace resulting in temp of direct path read and track direct writing temp waiting events taking too much time. Is it possible to set this query?

Thanks in advance.

user9074365 wrote:
Hi all
Oracle Database 10 g Enterprise Edition release 10.2.0.3.0 - 64bi
PL/SQL version 10.2.0.3.0 - Production
CORE Production 10.2.0.3.0
AMT for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - production
NLSRTL Version 10.2.0.3.0 - Production
I have a query that has analytic function uses space on temporary tablespace resulting in temp of direct path read and track direct writing temp waiting events taking too much time. Is it possible to set this query?

With your version of Oracle and high-volumes of data through the analytical function, it is likely that this blog note applies. You may need a patch upgrade or special. http://jonathanlewis.WordPress.com/2009/09/07/analytic-agony/

Concerning
Jonathan Lewis

Tags: Database

Similar Questions

  • Using Oracle analytic function

    Hi all

    I use Oracle 10 g Release 10.0.2

    Here's the situation:

    I visited in my table of looks like this:

    Cust_id beg_dt end_dt sg_cd

    264321502 1 MAY 97 19 MARCH 98 1

    264321502 21 MAY 98 15 OCTOBER 98 6

    264321502 20 OCTOBER 98 22 APRIL 99 6

    264321502 23 APRIL 99 25 APRIL 00 6

    264321502 27 APRIL 00 20 JANUARY 02 6

    264321502 25 JANUARY 02 15 MAY 02 6

    264321502 MAY 21 02 27 MAY 02 6

    264321502 31 MAY 02 17 FEBRUARY 03 6

    264321502 21 FEBRUARY 06 03-7.-04 1

    264321502 25 FEBRUARY 03 25 FEBRUARY 03 1

    264321502 31 MARCH 03 30 APRIL 03 1

    264321502 07 - SEP - 04 26 DECEMBER 04 6

    264321502 29 DECEMBER 04 3 JANUARY 06 6

    264321502 4 JANUARY 06 3 JANUARY 07 12

    264321502 4 JANUARY 06 3 JANUARY 07 12

    264321502 4 JANUARY 06 3 JANUARY 07 12

    I need the results of the query as

    Cust_id beg_dt end_dt sg_cd

    264321502 1 MAY 97 19 MARCH 98 1

    264321502 21 MAY 98 17 FEBRUARY 03 6

    264321502 21 FEBRUARY 03 30 APRIL 03 1

    264321502 07 - SEP - 04 3 JANUARY 06 6

    264321502 4 JANUARY 06 3 JANUARY 07 12

    Basically, I need take a min max (end_dt) of sg_cd for this cust id (beg_dt).

    Any help is very much appreciated:

    My query is like that

    Select cust_id, end_dt, beg_dt, sg_cd,

    min (beg_dt) more (partition of cust_id, sg_Cd) as new_beg_dt,

    Max (end_dt) more (partition of cust_id, sg_cd) as end_Dt_nw

    of cust_tab.

    can be like that?

    1 data

    () 2

    3 select Cust_id 264321502, to_date('01-MAY-97','dd-mon-rr') beg_dt, to_date('19-MAR-98','dd-mon-rr') end_dt, 1 sg_cd of all the double union

    4. Select 264321502, to_date('21-MAY-98','dd-mon-rr'), to_date('15-OCT-98','dd-mon-rr'), 6 Union double all the

    5 select 264321502, to_date('20-OCT-98','dd-mon-rr'), to_date('22-APR-99','dd-mon-rr'), 6 Union double all the

    6. Select 264321502, to_date('23-APR-99','dd-mon-rr'), to_date('25-APR-00','dd-mon-rr'), 6 Union double all the

    7. Select 264321502, to_date('27-APR-00','dd-mon-rr'), to_date('20-JAN-02','dd-mon-rr'), 6 Union double all the

    8 select 264321502, to_date('25-JAN-02','dd-mon-rr'), to_date('15-MAY-02','dd-mon-rr'), 6 Union double all the

    9. Select 264321502, to_date('21-MAY-02','dd-mon-rr'), to_date('27-MAY-02','dd-mon-rr'), 6 Union double all the

    10. Select 264321502, to_date('31-MAY-02','dd-mon-rr'), to_date('17-FEB-03','dd-mon-rr'), 6 Union double all the

    11. Select 264321502, to_date('21-FEB-03','dd-mon-rr'), to_date('06-SEP-04','dd-mon-rr'), 1 Union double all the

    12 select 264321502, to_date('25-FEB-03','dd-mon-rr'), to_date('25-FEB-03','dd-mon-rr'), 1 Union double all the

    13 select 264321502, to_date('31-MAR-03','dd-mon-rr'), to_date('30-APR-03','dd-mon-rr'), 1 Union double all the

    14 select 264321502, to_date('07-SEP-04','dd-mon-rr'), to_date('26-DEC-04','dd-mon-rr'), 6 Union double all the

    15 select 264321502, to_date('29-DEC-04','dd-mon-rr'), to_date('03-JAN-06','dd-mon-rr'), 6 Union double all the

    16 select 264321502, to_date('04-JAN-06','dd-mon-rr'), to_date('03-JAN-07','dd-mon-rr'), 12 Union double all the

    17 select 264321502, to_date('04-JAN-06','dd-mon-rr'), to_date('03-JAN-07','dd-mon-rr'), 12 Union double all the

    18 select 264321502, to_date('04-JAN-06','dd-mon-rr'), to_date('03-JAN-07','dd-mon-rr'), 12 of the double

    (19) - select * from data

    20. Select Cust_id, beg_dt, max (end_dt) as end_dt, min (beg_dt), sg_cd

    21 of

    (22)

    23 select x.*, sum (flg) over (order by end_dt Cust_id partition) as grp

    24 of

    (25)

    26 select

    27 wagneur, case when lag (sg_cd, 1-9) over (order by end_dt Cust_id partition)! sg_cd = 1 END so that flg

    28 from data d

    x 29)

    x 30)

    Group 31 by Cust_id, sg_cd, grp

    32 * order of Cust_id, end_dt

    CUST_ID BEG_DT END_DT SG_CD

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

    264321502 1 MAY 97 19 MARCH 98 1

    264321502 21 MAY 98 17 FEBRUARY 03 6

    264321502 21 FEBRUARY 06 03-7.-04 1

    264321502 07 - SEP - 04 3 JANUARY 06 6

    264321502 4 JANUARY 06 3 JANUARY 07 12

  • analytical functions in oracle

    Hi I am new to oracle analytical functions

    I do not know how to use and where to use real-time, please send me the useful any url for it.

    I read in the Oracle Documentation , but it's not understand for me.

    Please provide me with any other useful URL, I'll read to those.if you have examples, please report it in the present.

    Thank you

    Check this box:

    ORACLE-BASE - Analytic Functions

    Analytical functions for example. Oracle FAQ

  • Return one row of an analytic function

    Hello

    I pulled the following query:

    Select ID_STORNO, first_value (COD_CONTATTO) ON (Partition of COD_CONTATTO

    order of COD_PRIORITY asc, desc FT_DAT_OPEN_CNT

    rows between unbounded preceding and following unbounded)

    as COD_CONTATTO_LAST

    of WT_STR_ESG_CONTATTO;

    The result is:

    2160603C1-H83J1N
    2160603C8-9FOHXJS
    2258072C1-H83J1N

    But I just need to take the following lines

    2160603C8-9FOHXJS
    2258072C1-H83J1N

    Because for the same value of ID_STORNO, I just need to get a value of COD_CONTATTO (to select the best value using COD_PRIORITY and FT_DAT_OPEN_CNT). What is wrong inside the query? I just use 2 or 3 times the oracle analytic functions.

    Best regards

    As SomeoneElse... you need a where clause clause in order to choose the ones you want.

    To do this, the typical is to select a column that you use for this reason, such as:

    "I want to just the first record in each group..."

    Select id_storno, cod_contatto_last from)

    Select ID_STORNO, first_value (COD_CONTATTO) ON (Partition of COD_CONTATTO

    order of COD_PRIORITY asc, desc FT_DAT_OPEN_CNT

    rows between unbounded preceding and following unbounded)

    as COD_CONTATTO_LAST,

    ROW_NUMBER() OVER (Partition of COD_CONTATTO

    order of COD_PRIORITY asc, desc FT_DAT_OPEN_CNT

    rows between unbounded preceding and following unbounded)

    as rnum

    of WT_STR_ESG_CONTATTO

    )

    where rnum = 1

    /

    I prefer to use rownumber in this case, so I always have a rnum = 1...

    Usually, you must use the same partition/command by as your other folders (it is usually a good idea... maybe not, depending on your needs, however)

  • sensitive analytical function

    Hi all

    I am new to Oracle analytical functions, and I'll try to find the best way to write my query.

    What follows is a simplified version of a table, I work with...
    CREATE TABLE my_table
    (
        pid          NUMBER  NOT NULL,
        my_value     NUMBER,
        value_date   DATE    NOT NULL,
    
        CONSTRAINT pk_my_table PRIMARY KEY (pid, value_date)
    );
    Note that 'value_date' is part of the primary key.

    Each "pid", I would like to request to view 5 columns:
    1. The NEST
    2. the max value of "my_value" for the most recent 7 days of data
    3. the day correspondent (value_date) for the day 7 max
    4. the max value of "my_value" for the last 30 days of data
    5. the day (value_date) for the maximum of 30 days

    Is it possible to do without a join? What is the best way to achieve this?

    Thanks in advance for any help,

    Kal

    With the following test data:

    SQL> select * from my_table;
    
           PID   MY_VALUE VALUE_DAT
    ---------- ---------- ---------
             1        300 18-FEB-10
             1        200 17-FEB-10
             1       4500 16-FEB-10
             1        800 15-FEB-10
             1      12000 14-FEB-10
             1      21000 13-FEB-10
             1       5600 12-FEB-10
             1      18400 11-FEB-10
             1       7200 10-FEB-10
             1      24000 09-FEB-10
             1       8800 08-FEB-10
             1       6000 07-FEB-10
             1      44200 06-FEB-10
             1       2800 05-FEB-10
             1      58500 04-FEB-10
             1       8000 03-FEB-10
             1      30600 02-FEB-10
             1       7200 01-FEB-10
             1      62700 31-GEN-10
             1      48000 30-GEN-10
             1      16800 29-GEN-10
             1      83600 28-GEN-10
             1      18400 27-GEN-10
             1      16800 26-GEN-10
             1      40000 25-GEN-10
             1      23400 24-GEN-10
             1      99900 23-GEN-10
             1      67200 22-GEN-10
             1       5800 21-GEN-10
             1      57000 20-GEN-10
             1      96100 19-GEN-10
             1      64000 18-GEN-10
             1      52800 17-GEN-10
             1      71400 16-GEN-10
             1      14000 15-GEN-10
             1       7200 14-GEN-10
             1     111000 13-GEN-10
             1      64600 12-GEN-10
             1     113100 11-GEN-10
             1      84000 10-GEN-10
             2       6000 18-FEB-10
             2       7800 17-FEB-10
             2      13500 16-FEB-10
             2      25600 15-FEB-10
             2     276000 14-FEB-10
             2     210000 13-FEB-10
             2     162400 12-FEB-10
             2      36800 11-FEB-10
             2      86400 10-FEB-10
             2     480000 09-FEB-10
             2       8800 08-FEB-10
             2     102000 07-FEB-10
             2    1237600 06-FEB-10
             2      61600 05-FEB-10
             2    1287000 04-FEB-10
             2     144000 03-FEB-10
             2     275400 02-FEB-10
             2      93600 01-FEB-10
             2    1630200 31-GEN-10
             2    1248000 30-GEN-10
             2     235200 29-GEN-10
             2    3176800 28-GEN-10
             2      73600 27-GEN-10
             2     403200 26-GEN-10
             2     200000 25-GEN-10
             2     280800 24-GEN-10
             2     599400 23-GEN-10
             2    1612800 22-GEN-10
             2     110200 21-GEN-10
             2    1653000 20-GEN-10
             2    2498600 19-GEN-10
             2    2368000 18-GEN-10
             2     211200 17-GEN-10
             2    2570400 16-GEN-10
             2     224000 15-GEN-10
             2     223200 14-GEN-10
             2     999000 13-GEN-10
             2    2325600 12-GEN-10
             2    1017900 11-GEN-10
             2    2352000 10-GEN-10
    
    Selezionate 80 righe.
    

    Check this query:

    SQL> select pid
      2         ,max(case WHEN value_date>trunc(sysdate)-7 THEN my_value ELSE 0 END) MAX_7_days
      3         ,max(value_date) KEEP (dense_rank first order by (case WHEN value_date>trunc(sysdate)-7 THEN my_value ELSE 0 END) desc) DAY_7_DAYS
      4         ,max(case WHEN value_date>trunc(sysdate)-30 THEN my_value ELSE 0 END) MAX_30_DAYS
      5         ,max(value_date) KEEP (dense_rank first order by case WHEN value_date>trunc(sysdate)-30 THEN my_value ELSE 0 END desc) DAY_30_DAYS
      6    from my_table
      7  group by pid;
    
           PID MAX_7_DAYS DAY_7_DAY MAX_30_DAYS DAY_30_DA
    ---------- ---------- --------- ----------- ---------
             1      21000 13-FEB-10       99900 23-GEN-10
             2     276000 14-FEB-10     3176800 28-GEN-10
    

    Max
    http://oracleitalia.WordPress.com

    Published by: Massimo Ruocchio, February 18, 2010 21:03

  • Analytical function in Oracle

    I have a situation where I partitioned a Recordset. If in one partition on this recordset, the value of a field (field name registered) is '45' I need to order the result of this partition by - "outdate" desc "this provision" desc and order the other partition of desc 'key',' sequence ' desc, desc "outdate."

    If the query looks like to.

    Select row_number() over (partition by the order of the keys in sequence) RowNo, key, seq, status, outdate, receivedate from table1 where...
    order by?


    RowNo status outdate Seq key provision
    1 200 0 24 9/13 / 2009 12/9/2009
    2 200 1 23 9/10 / 2009 9/09/2009
    3 200 2 24 9/09 / 2009 9/08/2009

    1 210 0 24 9/13 / 2009 12/9/2009
    2 210 1 * 45 * 9/09/2009-9/08/2009
    3 210 2 24 9/10 / 2009 9/09/2009

    So I need to get the query that will order the first series of partition by desc 'key',' order ' desc, desc "outdate" and the second set of partition (because the status of '45' exists in the second partition) by "outdate" desc "this provision" desc.

    The output of the query should look like

    RowNo status outdate Seq key provision
    1 200 0 24 9/13 / 2009 12/9/2009
    2 200 1 23 9/10 / 2009 9/09/2009
    3 200 2 24 9/09 / 2009 9/08/2009

    1 210 0 24 9/13 / 2009 12/9/2009
    2 210 2 24 9/10 / 2009 9/09/2009
    3 210 1 * 45 * 9/09/2009-9/08/2009

    I don't know if this is possible using the analytical function.

    I would appreciate if any can help me with that.

    Thanks in advance

    Hello

    Welcome to the forum!

    You can use analytical functions in the ORDER BY clause.

    I do not have your tables, so I'll use scott.emp to illustrate.

    The following query sorts first by deptno. After this, the sort order for the departments that contain at least one seller is:
    b job
    (b) ename
    DEPTNO = 30 is be the only Department with a seller, so it's the only sorting as shown above.
    Other departments will be sorted by
    (a) sal
    (b) job

    SELECT       deptno
    ,       ename
    ,       job
    ,       sal
    FROM       scott.emp
    ORDER BY  deptno
    ,            CASE
              WHEN  COUNT ( CASE
                                   WHEN  job = 'SALESMAN'
                          THEN  1
                         END
                       ) OVER (PARTITION BY deptno) > 0
              THEN  ROW_NUMBER () OVER ( PARTITION BY  deptno
                                          ORDER BY        job
                                ,            ename
                              )
              ELSE  ROW_NUMBER () OVER ( PARTITION BY  deptno
                                          ORDER BY        sal
                                ,            job
                              )
           END
    ;
    

    Output:

    .   DEPTNO ENAME      JOB              SAL
    ---------- ---------- --------- ----------
            10 MILLER     CLERK           1300
            10 CLARK      MANAGER         2450
            10 KING       PRESIDENT       5000
            20 SMITH      CLERK            800
            20 ADAMS      CLERK           1100
            20 JONES      MANAGER         2975
            20 SCOTT      ANALYST         3000
            20 FORD       ANALYST         3000
            30 JAMES      CLERK            950
            30 BLAKE      MANAGER         2850
            30 ALLEN      SALESMAN        1600
            30 MARTIN     SALESMAN        1250
            30 TURNER     SALESMAN        1500
            30 WARD       SALESMAN        1250
    

    The small set of sample data you posted, the results you want can be achieved simply through

    ORDER BY  key
    ,         outdate     DESC
    

    I guess it's just a coincidence.

    If you need help, post some examples of data that requires really looking at the status column to get good results. Display the data in executable form, such as CREATE TABLE and the instructions INSERT, olr, as Salim, a WITH clause. (Maybe you can simply add or change a couple of lines in the example Salim already posted data).

  • Order of evaluation of analytic function

    Hello

    have question quite like this:

    with

    -This query selects a 'representative' acct_id by Group (about 300 lines in total)

    acct_repres as

    (

    Select distinct acct_id, origin_id, acct_parm_id of

    (

    Select a.*

    source_id

    , dense_rank() over (partition by order source_id by nulls first, acct_id acct_nbr origin_id) as odr

    account a join account_parm on (a.parm_id = ap.acct_parm_id) ap

    )

    where odr = 1

    )

    Select col1

    col2

    , (select accct_id from ar acct_repres where ar.acct_parm_id = t2.acct_parm_id) col3

    , col4 (select count (1) of acct_repres)

    of une_table t1

    Join other_table t2 on (...)

    And here it is. "Acct_repres" subquery returns more than 300 lines when it is run separately. But when it is used in CTE sometimes (depending on the execution plan) she seems to have that one line - the value in the column col4 is '1 ',.

    While the value of col3 is NULL for most of the cases.

    It looks like the the dense_rank function and the State 'where odr = 1' are evaluated at the end.

    When I use the hint to MATERIALIZE the result was the same.

    But when I put the result of account_repres in the dedicated table and use this table instead of CTE output is correct.

    What is a bug? Or I do something wrong?

    PS: my version of db is 11 GR 1 material (11.1.0.7).

    some unorganized comments:

    -analytical functions are evaluated towards the end of the execution ("' the last set of operations performed in a query with the exception of the final ORDER BY clause"- http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm")

    -but still the result of a SQL query must be deterministic, so I think that your results are not an expected behavior

    -the CBO has some problems with common table expressions (http://jonathanlewis.wordpress.com/2012/05/24/subquery-factoring-7/) if they are of great assistance in the structuring of complex queries. In these cases, you can avoid problems by using inline views

    -Your query uses the common table expressions in scalar subqueries and scalar subqueries are also likely to confuse the CBO. In addition, they are executed once for each row in your result set (or at least for each different correlation value) and can have a negative impact on the performance of the queries in many cases. Often, they can be replaced by outer joins.

    -you say that the suspicion of materialization brings you an erroneous result: the indicator object (online) gives you the correct results?

    Concerning

    Martin Preiss

  • Problem with analytical function for date

    Hi all

    ORCL worm:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE 11.2.0.2.0 Production."
    AMT for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    I have a problem with the analtical for the date function. I'm trying to group records based on timestamp, but I'm failing to do.
    Could you please help me find where I'm missing.
    This is the subquery. No issue with this. I'm just posting it for reference. 
    select sum(disclosed_cost_allocation.to_be_paid_amt) amt,
        substr(reference_data.ref_code,4,10) cd,
        to_char(external_order_status.status_updated_tmstp, 'DD-MON-YYYY HH24:MI:SS') tmstp,
        DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID id
      FROM Deal.Fee_Mapping_Definition ,
        Deal.Fee_Index_Definition ,
        Deal.Fee_Closing_Cost_Item,
        Deal.Closing_Cost,
        Deal.Document_Generation_Request,
        deal.PRODUCT_REQUEST,
        deal.External_Order_Request,
        deal.External_Order_Status,
        deal. DISCLOSED_CLOSING_COST,
        deal.DISCLOSED_COST_ALLOCATION,
        deal.reference_data
      WHERE Fee_Mapping_Definition.Fee_Code                    = Fee_Index_Definition.Fee_Code
      AND Fee_Index_Definition.Fee_Index_Definition_Id         = Fee_Closing_Cost_Item.Fee_Index_Definition_Id
      AND Fee_Closing_Cost_Item.Closing_Cost_Id                = Closing_Cost.Closing_Cost_Id
      AND CLOSING_COST.PRODUCT_REQUEST_ID                      = Document_Generation_Request.Product_Request_Id
      AND closing_cost.product_request_id                      = product_request.product_request_id
      AND Product_Request.Deal_Id                              = External_Order_Request.Deal_Id
      AND external_order_request.external_order_request_id     = external_order_status.external_order_request_id
      AND external_order_request.external_order_request_id     = disclosed_closing_cost.external_order_request_id
      AND DISCLOSED_CLOSING_COST. DISCLOSED_CLOSING_COST_ID    = DISCLOSED_COST_ALLOCATION.DISCLOSED_CLOSING_COST_ID
      AND Fee_Index_Definition.Fee_Index_Definition_Id         = Disclosed_Closing_Cost.Fee_Index_Definition_Id
      AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id   = Reference_Data.Reference_Data_Id
      AND Document_Generation_Request.Document_Package_Ref_Id IN (7392 ,2209 )
      AND External_Order_Status.Order_Status_Txt               = ('GenerationCompleted')
      AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id  IN ( 7789, 7788,7596 )
      AND FEE_MAPPING_DEFINITION.DOCUMENT_TYPE_REF_ID          = 1099
      AND Document_Generation_Request.Product_Request_Id      IN
        (SELECT PRODUCT_REQUEST.PRODUCT_REQUEST_id
        FROM Deal.Disclosed_Cost_Allocation,
          Deal.Disclosed_Closing_Cost,
          DEAL.External_Order_Request,
          DEAL.PRODUCT_REQUEST,
          Deal.Scenario
        WHERE Disclosed_Cost_Allocation.Disclosed_Closing_Cost_Id = Disclosed_Closing_Cost.Disclosed_Closing_Cost_Id
        AND Disclosed_Closing_Cost.External_Order_Request_Id      = External_Order_Request.External_Order_Request_Id
        AND External_Order_Request.Deal_Id                        = Product_Request.Deal_Id
        AND product_request.scenario_id                           = scenario.scenario_id
        AND SCENARIO.SCENARIO_STATUS_TYPE_REF_ID                  = 7206
        AND product_request.servicing_loan_acct_num              IS NOT NULL
        AND product_request.servicing_loan_acct_num               = 0017498379
          --AND Disclosed_Cost_Allocation.Disclosed_Cost_Allocation_Id = 5095263
        )
      GROUP BY DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID,
        External_Order_Status.Status_Updated_Tmstp,
        Reference_Data.Ref_Code,
        disclosed_cost_allocation.to_be_paid_amt
      order by 3 desc,
        1 DESC;
    
    Result:
    2000     1304-1399     28-JUL-2012 19:49:47     6880959
    312     1302     28-JUL-2012 19:49:47     6880958
    76     1303     28-JUL-2012 19:49:47     6880957
    2000     1304-1399     28-JUL-2012 18:02:16     6880539
    312     1302     28-JUL-2012 18:02:16     6880538
    76     1303     28-JUL-2012 18:02:16     6880537
    
    
    But, when I try to group the timestamp using analytical function,
    
    
    select amt 
            ,cd 
            ,rank() over(partition by tmstp order by tmstp desc) rn 
    from 
    (select sum(disclosed_cost_allocation.to_be_paid_amt) amt,
        substr(reference_data.ref_code,4,10) cd,
        to_char(external_order_status.status_updated_tmstp, 'DD-MON-YYYY HH24:MI:SS') tmstp,
        DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID id
      FROM Deal.Fee_Mapping_Definition ,
        Deal.Fee_Index_Definition ,
        Deal.Fee_Closing_Cost_Item,
        Deal.Closing_Cost,
        Deal.Document_Generation_Request,
        deal.PRODUCT_REQUEST,
        deal.External_Order_Request,
        deal.External_Order_Status,
        deal. DISCLOSED_CLOSING_COST,
        deal.DISCLOSED_COST_ALLOCATION,
        deal.reference_data
      WHERE Fee_Mapping_Definition.Fee_Code                    = Fee_Index_Definition.Fee_Code
      AND Fee_Index_Definition.Fee_Index_Definition_Id         = Fee_Closing_Cost_Item.Fee_Index_Definition_Id
      AND Fee_Closing_Cost_Item.Closing_Cost_Id                = Closing_Cost.Closing_Cost_Id
      AND CLOSING_COST.PRODUCT_REQUEST_ID                      = Document_Generation_Request.Product_Request_Id
      AND closing_cost.product_request_id                      = product_request.product_request_id
      AND Product_Request.Deal_Id                              = External_Order_Request.Deal_Id
      AND external_order_request.external_order_request_id     = external_order_status.external_order_request_id
      AND external_order_request.external_order_request_id     = disclosed_closing_cost.external_order_request_id
      AND DISCLOSED_CLOSING_COST. DISCLOSED_CLOSING_COST_ID    = DISCLOSED_COST_ALLOCATION.DISCLOSED_CLOSING_COST_ID
      AND Fee_Index_Definition.Fee_Index_Definition_Id         = Disclosed_Closing_Cost.Fee_Index_Definition_Id
      AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id   = Reference_Data.Reference_Data_Id
      AND Document_Generation_Request.Document_Package_Ref_Id IN (7392 ,2209 )
      AND External_Order_Status.Order_Status_Txt               = ('GenerationCompleted')
      AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id  IN ( 7789, 7788,7596 )
      AND FEE_MAPPING_DEFINITION.DOCUMENT_TYPE_REF_ID          = 1099
      AND Document_Generation_Request.Product_Request_Id      IN
        (SELECT PRODUCT_REQUEST.PRODUCT_REQUEST_id
        FROM Deal.Disclosed_Cost_Allocation,
          Deal.Disclosed_Closing_Cost,
          DEAL.External_Order_Request,
          DEAL.PRODUCT_REQUEST,
          Deal.Scenario
        WHERE Disclosed_Cost_Allocation.Disclosed_Closing_Cost_Id = Disclosed_Closing_Cost.Disclosed_Closing_Cost_Id
        AND Disclosed_Closing_Cost.External_Order_Request_Id      = External_Order_Request.External_Order_Request_Id
        AND External_Order_Request.Deal_Id                        = Product_Request.Deal_Id
        AND product_request.scenario_id                           = scenario.scenario_id
        AND SCENARIO.SCENARIO_STATUS_TYPE_REF_ID                  = 7206
        AND product_request.servicing_loan_acct_num              IS NOT NULL
        AND product_request.servicing_loan_acct_num               = 0017498379
          --AND Disclosed_Cost_Allocation.Disclosed_Cost_Allocation_Id = 5095263
        )
      GROUP BY DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID,
        External_Order_Status.Status_Updated_Tmstp,
        Reference_Data.Ref_Code,
        disclosed_cost_allocation.to_be_paid_amt
      order by 3 desc,
        1 DESC);
    
    Result:
    312     1302            1
    2000     1304-1399     1
    76     1303            1
    312     1302            1
    2000     1304-1399     1
    76     1303            1 
    
    
    Required output:
    312     1302            1
    2000     1304-1399     1
    76     1303            1
    312     1302            2
    2000     1304-1399     2
    76     1303            2
    THX
    Rod.

    Hey, Rod,

    My guess is that you want:

    , dense_rank () over (order by  tmstp  desc)  AS rn 
    

    RANK means you'll jump numbers when there is a link. For example, if all 3 rows have the exact same last tmstp, all 3 rows would be assigned number 1, GRADE would assign 4 to the next line, but DENSE_RANK attributes 2.

    "PARTITION x" means that you are looking for a separate series of numbers (starting with 1) for each value of x. If you want just a series of numbers for the entire result set, then do not use a PARTITION BY clause at all. (PARTITION BY is never required.)
    Maybe you want to PARTITIONNER IN cd. I can't do it without some examples of data, as well as an explanation of why you want the results of these data.
    You certainly don't want to PARTITION you BY the same expression ORDER BY; It simply means that all the lines are tied for #1.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Simplify the problem as much as possible.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

    Published by: Frank Kulash, August 1, 2012 13:20

  • analytical function and the aggregate function

    What are the analytical function and the aggregate function. What is the difference between them?

    Hello

    Analytic Functions : -.

    Analytical functions calculate a value of aggregation based on a group of lines. They differ from aggregate functions because they return several rows for each group. The Group of rows is called a window and is defined by the analytic_clause. For each line, a sliding window of lines is defined. The window determines the range of lines used for the calculations for the current line. Window sizes can be based on a physical number of rows or a logic as the time interval.
    Analytical functions are the last set of operations performed in a query with the exception of the last ORDER BY clause. Every joint and every WHERE, GROUP BY and HAVING clauses are met before the analytical functions are handled. As a result, analytic functions can only appear in the select list or the ORDER BY clause.
    Analytical functions are commonly used to calculate cumulative aggregates, moving, centered and considered.

    Aggregate functions : -.

    Aggregate functions return a line of single result based on the groups of lines, rather than on the unique lines. Aggregate functions can appear in selection lists, as well as in the HAVING and ORDER BY clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database splits the rows in a table when asked or seen in groups. In a query that contains a GROUP BY clause, the select list items can be aggregation functions, GROUP BY constant expressions or expressions involving one of them. Oracle applies the functions of aggregation for each group of rows and returns a single result for each group line.
    If you omit the GROUP BY clause, Oracle then applies any aggregate functions in the select list for all rows in the table queried or the view. You use aggregate functions in the HAVING clause to eliminate groups of the output based on the results of aggregate functions, rather than the values of the individual lines of the queried table or view.

    Let me know if you feel any problem understanding.
    Thank you.

    Published by: varun4dba on January 27, 2011 15:32

  • Which analytical function to use?


    Hi gurus,

    DB - Oracle 11 g 2

    I followed the examples of data in the table test_a.

    col1 col2 col3

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

    x                 y                   y

    p                 q                  y

    a                b                   y

    p                q                   y

    t                 r                    y

    p                q                   y

    The col3 column is always 'y '. But here's the data p, q, there is repeated 3 times (duplicate) and if this is the case I want to update only the first recordings like "n" col3 it is to say p, q, n. rest will be as it is.

    I am able to get the row_number() for it but not able to do this.

    Select col1, clo2, clo3 row_number() over (partition by col2) arrested by col1 as test_a r_num

    Would it be possible directly by any analytic function?

    Thank you

    SID

    COL4 is logical...

    Something like that?

    with x as)

    Select col1, col2 ' x' 'y', 'y' col3 col4 1 Union double all the

    Select 'p' col1, col2 'q', 'y' col3 col4 2 Union double all the

    Select 'a' col1, col2 'b', 'y' col3 col4 3 of all the double union

    Select 'p' col1, col2 'q', 'y' col3 col4 4 Union double all the

    Select 't' col1, col2 'r', 'y' col3, col4 5 Union double all the

    Select 'p' col1, col2 'q', 'y' col3 col4 6 double

    )

    ---

    Select * from)

    Select x.*,

    ROW_NUMBER() on rn1 (score of col1, col2, col3 col4 sort),

    ROW_NUMBER() on rn2 (partition by col1, col2, col3 col4 desc sorting)

    x

    )

    where rn1 = 1 and rn2 <> 1;

    Understand the logic and simply change SELECT a query to UPDATE...

  • Using the analytic function

    Oracle 11g Release 2

    I'm assuming that the best solution is the use of analytical functions.

    create table test3
    ( part_type_id  varchar2(50)
    ,group_id      number
    ,part_desc_id  number
    ,part_cmt      varchar2(50)
    )
    /
    
    insert into test3 values( 'ABC123',1,10,'comment1');
    insert into test3 values( 'ABC123',1,10,'comment2');
    insert into test3 values( 'ABC123',2,15,'comment1');
    insert into test3 values( 'ABC123',2,15,'comment2');
    insert into test3 values( 'EFG123',25,75,'comment3');
    insert into test3 values( 'EFG123',25,75,'comment4');
    insert into test3 values( 'EFG123',25,75,'comment5');
    insert into test3 values( 'XYZ123',1,10,'comment6');
    insert into test3 values( 'XYZ123',2,15,'comment7');
    commit;
    
    select * from test3;
    
    PART_TYPE_ID           GROUP_ID PART_DESC_ID PART_CMT
    -------------------- ---------- ------------ --------------------
    ABC123                        1           10 comment1
    ABC123                        1           10 comment2
    ABC123                        2           15 comment1
    ABC123                        2           15 comment2
    EDG123                        25          75 comment3
    EDG123                        25          75 comment4
    EDG123                        25          75 comment5
    XYZ123                        1           10 comment6
    XYZ123                        2           15 comment7
    
    9 rows selected.
    
    Desired output:
    
    PART_TYPE_ID           GROUP_ID PART_DESC_ID PART_CMT
    -------------------- ---------- ------------ --------------------
    ABC123                        1           10 comment1 
    ABC123                        2           15 comment1
    XYZ123                        1           10 comment1
    XYZ123                        2           15 comment2
    
    RULE: where one part_type_id has multiple (2 or more distinct combinations) of group_id/part_desc_id
    
    NOTE: There are about 12 columns in the table, for brevity I only included 4.
    
    
    
    

    Post edited by: orclrunner was updated desired output and rule

    Hello

    Here's one way:

    WITH got_d_count AS

    (

    SELECT part_type_id, group_id, part_desc_id

    MIN (part_cmt) AS min_part_cmt

    COUNT AS d_count (*) OVER (PARTITION BY part_type_id)

    OF test3

    GROUP BY part_type_id, group_id, part_desc_id

    )

    SELECT DISTINCT

    group_id, part_desc_id, part_type_id, min_part_cmt

    OF got_d_count

    WHERE d_count > 1

    ;

    Output:

    GROUP_ID PART_DESC_ID MIN_PART_CMT PART_TYPE_ID

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

    ABC123 1 10 comment1

    ABC123 2 15 comment1

    XYZ123 1 10 comment6

    XYZ123 2 15 comment7

    Analytical functions, such as the COUNTY and MIN, many global versions, in addition, it can give the same results.  Use the analytical versions when each row of output corresponds to exactly 1 row of input and the aggregate and GROUP BY version when each line of output corresponds to a group of lines 1 or more input.  In this issue, each line of output appears to be a group of input lines having the same group_id, part_type_id, and part_desc_id (I'm guessing just, this only has never stated), so I used GROUP BY to get 1 row of output for every input lines.

  • Why the different values for an analytic function of the same group/game

    I have the suite of table I'll be using.

    Select * from table1;

    REC_ID | STATUS | DATE_FROM | DATE_TO

    1. C | 7 January 2015 |

    2. H | December 3, 2014. 6 January 2015

    3. H | October 3, 2014. December 2, 2014

    4. H | May 30, 2014. October 2, 2014

    5. H | May 29, 2014 | May 29, 2014

    6. H | April 16, 2014 | May 28, 2014

    7. H | Tuesday, April 25, 2007 April 15, 2014

    INSERT statement if you need.

    TOGETHER TO DEFINE

    CREATE THE TABLE1 TABLE:

    (

    NUMBER OF REC_ID,

    VARCHAR2 (1 BYTE) STATUS NOT NULL,.

    DATE_FROM DATE NOT NULL,

    DATE OF DATE_TO

    );

    Insert into TABLE1

    (REC_ID, STATUS, DATE_FROM)

    Values

    (1, 'C', TO_DATE (7 JANUARY 2015 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into TABLE1

    (REC_ID, STATUS, DATE_FROM, DATE_TO)

    Values

    (2, 'H', TO_DATE (3 DECEMBER 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (6 JANUARY 2015 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into TABLE1

    (REC_ID, STATUS, DATE_FROM, DATE_TO)

    Values

    (3, 'H', TO_DATE (3 OCTOBER 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (2 DECEMBER 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into TABLE1

    (REC_ID, STATUS, DATE_FROM, DATE_TO)

    Values

    (4, 'H', TO_DATE (MAY 30, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (2 OCTOBER 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into TABLE1

    (REC_ID, STATUS, DATE_FROM, DATE_TO)

    Values

    (5, 'H', TO_DATE (29 MAY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (29 MAY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into TABLE1

    (REC_ID, STATUS, DATE_FROM, DATE_TO)

    Values

    (6, 'H', TO_DATE (APRIL 16, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (28 MAY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))

    Insert into TABLE1

    (REC_ID, STATUS, DATE_FROM, DATE_TO)

    Values

    (7, 'H', TO_DATE (APRIL 25, 2007 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (APRIL 15, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))

    COMMIT;

    I will exercise more analytical query...

    Select rec_id date_from, date_to, status,

    min (date_from) over (partition by order of status by date_from desc) min_dt_from_grp,

    ROW_NUMBER() over (partition by order of status by date_from desc) rownumberdesc,

    ROW_NUMBER() over (partition by order of status by ASC date_from) rownumberasc

    FROM table1;

    the query result

    REC_ID | DATE_FROM | DATE_TO | STATUS | MIN_DT_FROM_GRP | ROWNUMBERDESC | ROWNUMBERASC

    1. 7 January 2015 | C | 7 January 2015 | 1. 1

    2. December 3, 2014. 6 January 2015 | H | December 3, 2014. 1. 6

    3. October 3, 2014. December 2, 2014 | H | October 3, 2014. 2. 5

    4. May 30, 2014. October 2, 2014 | H | May 30, 2014. 3. 4

    5. May 29, 2014 | May 29, 2014 | H | May 29, 2014 | 4. 3

    6. April 16, 2014 | May 28, 2014. H | April 16, 2014 | 5. 2

    7. Tuesday, April 25, 2007 April 15, 2014. H | Tuesday, April 25, 2007 6. 1

    If you look at the output above, it dates back in the min_dt_from_grp column.

    MY question is if the analytical function calculates for a particular/set group, which is by statute and for what min (date_from) partition is 25-apr-2007 for the GROUP H (Status column), then why I have different values returned by the query above in the min_dt_from_grp column.

    Hello

    Because you have specified an ORDER BY clause for the analytical function. In doing so, you calculate the rows on a window. Since you have not specified a windowing clause, the default applies:

    RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW

  • Analytical functions: FIRST vs FIRST_VALUE

    Hello

    Can someone please help me understand the difference between PRIME and FIRST_VALUE in Anaytic functions.

    I tried below 2 queries, but I see the same output. The only difference I see is that the field of the SAL is ordered FIRST_VALUE, but not the FIRST.

    SELECT ename,

    DEPTNO,

    SAL,

    MIN (SAL) keep (dense_rank FIRST

    ORDER BY sal) by (deptno partition) FIRST

    EMP;

    SELECT ename,

    DEPTNO,

    SAL,

    FIRST_VALUE (SAL) over (partition BY deptno arrested by sal) FIRST

    EMP;

    With the help of: Windows 8.1

    Database Oracle 12 c Enterprise Edition Release 12.1.0.1.0 - 64 bit Production

    PL/SQL Release 12.1.0.1.0 - Production

    "CORE 12.1.0.1.0 Production."

    AMT for 64-bit Windows: Version 12.1.0.1.0 - Production

    NLSRTL Version 12.1.0.1.0 - Production

    Hello

    Here is an example of when you can use the FIRST analytic function.

    Say you want the average sal for each Department, but only for the first year (taken from the hiredate column) in the Department (i.e., the column called f in the query below).

    WITH got_hireyear AS

    (

    SELECT deptno and ename, sal, hiredate

    EXTRACT (YEAR FROM hiredate) AS hireyear

    FROM scott.emp

    )

    SELECT deptno, hireyear, hiredate, ename, sal

    AVG (sal) DUNGEON (DENSE_RANK FIRST ORDER BY hireyear)

    COURSES (PARTITION BY deptno

    ) In the FORM f

    FIRST_VALUE (sal) over (PARTITION BY deptno

    ORDER BY hireyear

    ) AS fv

    AVG (sal) over (PARTITION BY deptno

    hireyear

    ), A

    OF got_hireyear

    ORDER BY deptno

    hireyear

    ename

    ;

    Output:

    HIREYEAR ENAME SAL HIREDATE DEPTNO F FV HAS
    ------ ---------- ----------- ---------- ------ --------- ------ ---------
    10 1981 9 June 1981 CLARK 2450 2450 3725,00 3725.00
    10 1981 17 November 1981 KING 5000 3725,00 2450 3725.00
    10 1982 23 January 1982 MILLER 1300 3725,00 2450 1300.00

    20, 1980, 17 December 1980 SMITH 800 800.00 800.00 800
    20, 1981, 3 December 1981 FORD 3000 800.00 800 2987.50
    20, 1981, 2 April 1981 JONES 2975 800.00 800 2987.50
    20, 1987, 23 May 1987 ADAMS 1100 800.00 800 2050.00
    20, 1987, 19 April 1987 SCOTT 3000 800.00 800 2050.00

    30 1981 20 February 1981 ALLEN 1600 1566.67 950 1566.67
    May 30 1981 1st 1981 BLAKE 2850 1566.67 950 1566.67
    December 30 1981 3 1981 JAMES 950 1566.67 950 1566.67
    30 1981 28 - sep - 1981 MARTIN 1250 1566.67 950 1566.67
    30-08 - sep - 1981 1981 TURNER 1500 1566.67 950 1566.67
    30 1981 22 February 1981 WARD 1250 1566.67 950 1566.67

    The analytical FIRST_VALUE function can do (except in the very special case where only 1 row has the lowest hireyear, as in deptno = 20).  AVG analysis can do (except in the very special case that all lines have the same hireyear as in deptno = 30).

  • without analytic function

    Hello experts.

    I have data similar to what follows below

    create table t1
    (
      id number(30),
      description varchar(4000)
    
    
    );
    
    insert into t1 values (1, 'zone');
    insert into t1 values (2, 'small');
    
    
    create table t2
    (
       id number(30),
       place varchar(4000),
       info varchar(4000)
    
    );
    
    insert into t2 values (1, 'USA', 'Class U');
    insert into t2 values (1, 'Mexico', 'Class M');
    insert into t2 values (2, 'Germany', 'Class G');
    

    I need help with something similar to what follows below without using any analytic function

    Description of the ID info Place

    1 box USA class U

    Mexico 1 M class

    2 small Germany class G

    Any help is appreciated. Thank you

    Hello

    user13328581 wrote:

    ... I use an older version of oracle. Oracle 7.

    Normally, your developers are older than your software.

    You should be able to do what you want with a self-join on t2; a copy (d) should be displayed, and the other copy (c) contains all related values you need for comparison.

    SELECT t2d.id

    DECODE (t2d.place

    MAX (t2c.place)

    t1.description

    ) AS description

    t2d.place

    t2d.info

    FROM t1

    , t2 t2d - display

    t2 t2c - compare

    WHERE t1.id = t2d.id

    AND t2d.id = t2c.id

    GROUP BY t1.description

    t2d.id

    t2d.place

    t2d.info

    ORDER BY t2d.id

    t2d.place DESC

    ;

    Output:

    ID DESCRIPTION PLACE INFO

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

    1 box USA class U

    Mexico 1 M class

    2 small Germany class G

    I've tested this in Oracle 11, but it should work in Oracle 7.

    If this isn't the case, you may need to create a view.

  • Analytical function?

    Hello

    I have two tables b rates and transactions (b).

    For each b.FS, I want to know new amount (b.amt time a.rate to the corresponding line of FS b and if a.na is valid based on the flag of the exclusion and the interval defined in the table's).

    It is much easier to explain with an example.

    So here we go...

    Exclude_flag = E (exclude): for b.fs = 433638, b.na = 80000. I have 2 lines in the table for this fs.  Both have E exclude_flag (exclude).  I want to go on all the lines in this FS in the table in a query and I return only one row in the result, if and only if b.na falls out of scope of a.na_min_value and a.na_max_values.  In this example, it falls outside the range excluded for both lines (first two lines of the table a).

    Similarly, exclude_flag = I (Include). for b.fs = 432828, b.na = 17200. I have 2 lines in the table for this fs.  Both have an exclude_flag of I (include).  I want to go on all the lines in this FS in the table in a query and I return only one row in the result, if and only if b.na is between a.na_min_value and a.na_max_values.  In this example, it falls in the range of both the range include for the two lines (line 6 and 7 of the table a).

    The following query gives me two lines for each b.fs.  It is possible to get what I'm looking for simply using sql (possibly write the analytical function?) or I have to write the pl/sql routine for this?

    WITH rates_table

    Did YOU (select ' E' include_exclude_flag, "81000 ' na_min_value, na_max_value '81999', '433638' FS, 0.8 of double rate

    UNION

    Select 'E' include_exclude_flag, na_min_value '84000', na_max_value '84999', '433638' FS, 0.8 of double rate

    UNION

    Select 'I' include_exclude_flag, na_min_value '12000', na_max_value '12999', '432828' FS, rate 0.25 double

    UNION

    Select 'I' include_exclude_flag, na_min_value '13000', na_max_value '13999', '432828' FS, rate 0.25 double

    UNION

    Select 'I' include_exclude_flag, na_min_value '15000', na_max_value '15000', '432828' FS, rate 0.25 double

    UNION

    Select 'I' include_exclude_flag, na_min_value '16100', na_max_value '18000', '432828' FS, rate 0.25 double

    UNION

    Select 'I' include_exclude_flag, '17100' na_min_value, na_max_value '18000', '432828' FS, rate 0.25 double

    UNION

    Select 'I' include_exclude_flag, na_min_value '02440', na_max_value '02470', '016532' FS, 0.35 rate double

    UNION

    Select 'E' include_exclude_flag, na_min_value ' 21000 ', '21000' na_max_value, ' 200020' FS, 0.35 double rate).

    transaction_table AS

    (select '433638' FS '80000' NA, 300 double amt)

    Union

    Select '432828' FS '17200' NA, amt 500 double

    )

    Select * from rates_table a, transaction_table b

    where 1 = 1

    and ((b.na PAS entre a.na_min_value et a.na_max_value et a.include_exclude_flag = «E») GOLD ())

    b.na between a.na_min_value and a.na_max_value and a.include_exclude_flag = 'I'))

    and b.fs = a.fs

    ;

    Any help is greatly appreciated.  I use oracle 11i

    @OP,

    For this kind of problems, we get the number of rows that satisfy the required conditions or who do not meet the required conditions. And then eliminate the line that should be eliminated.

    As below, I calculate four counts (number of join lines)

    EOBCNT - excluded and Out of Bound

    EIBCNT - excluded and in the limit

    IOBCNT - included and Out of Bound

    IIBCNT - included and within the limits

    Once those are calculated, simply return the lines that have EIBCNT and IOBCNT are zero.

    For Ex:

    > WITH

    rates_table

    AS LONG AS)

    Select 'E' include_exclude_flag, na_min_value '79999', na_max_value '79999', '433638' FS, 0.8 double UNION rates

    -Select 'E' include_exclude_flag, na_min_value ' 79999', na_max_value '80000', '433638' FS, 0.8 double UNION rate - TEST - THE

    -If you uncomment the last line and then 433638 will not be returned

    Select 'E' include_exclude_flag, "81000 ' na_min_value, na_max_value '81999', '433638' FS, 0.8 double UNION rates

    Select 'E' include_exclude_flag, na_min_value '84000', na_max_value '84999', '433638' FS, 0.8 double UNION rates

    Select 'I' include_exclude_flag, na_min_value '12000', na_max_value '12999', '432828' FS, 0.25 rate double UNION

    Select 'I' include_exclude_flag, na_min_value '13000', na_max_value '13999', '432828' FS, 0.25 rate double UNION

    Select 'I' include_exclude_flag, na_min_value '15000', na_max_value '15000', '432828' FS, 0.25 rate double UNION

    Select 'I' include_exclude_flag, na_min_value '16100', na_max_value '18000', '432828' FS, 0.25 rate double UNION

    Select 'I' include_exclude_flag, '17100' na_min_value, na_max_value '18000', '432828' FS, 0.25 rate double UNION

    Select 'I' include_exclude_flag, na_min_value '02440', na_max_value '02470', '016532' FS, 0.35 rate double UNION

    Select 'E' include_exclude_flag, na_min_value ' 21000 ', '21000' na_max_value, ' 200020' FS, 0.35 double rate).

    transaction_table AS

    (select '433638' FS '80000' NA, amt 300 Union double

    Select '432828' FS '17200' NA, amt 500 double

    )

    getcnts as)

    SELECT a.*

    b.na, b.amt

    , sum (case when (b.na NOT BETWEEN a.na_min_value)

    AND a.na_max_value

    AND a.include_exclude_flag = 'E '.

    end) then 1 else 0) on (a.fs partition) Eobcnt

    , sum (case when (b.na NOT BETWEEN a.na_min_value)

    AND a.na_max_value

    AND a.include_exclude_flag = 'I '.

    end) then 1 else 0) on (a.fs partition) Iobcnt

    , sum (case when (b.na BETWEEN a.na_min_value)

    AND a.na_max_value

    AND a.include_exclude_flag = 'E '.

    end) then 1 else 0) on (a.fs partition) Eibcnt

    , sum (case when (b.na BETWEEN a.na_min_value)

    AND a.na_max_value

    AND a.include_exclude_flag = 'I '.

    end) then 1 else 0) on (a.fs partition) Iibcnt

    OF rates_table one

    transaction_table b

    WHERE b.fs = a.fs

    )

    getrows as)

    Select x.*, row_number() on

    (partition by order of fs with null desc) getcnts rn x

    where IOBCNT = 0 and eibcnt = 0 - remove lines that are not needed (IF and ONLY if)

    )

    Select * from getrows

    where rn = 1 - to limit a SINGLE row (arbitrarily)

    INCLUDE_EXCLUDE_FLAG NA_MIN_VALUE NA_MAX_VALUE FS RATE NA AMT EOBCNT IOBCNT EIBCNT IIBCNT RN

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

    433638 84999 84000.8 E 80000 300 3 0 0 0 1

    I hope this helps.

Maybe you are looking for

  • Scanning from feeder OfficeJet Pro 8500 has

    I tried to search several times but I can't seem to find anything that addresses this specifically. I'm trying to scan multiple pages on my OfficeJet 8500 a on a machine running XP.  I deally I would that they in a single file, but if not possible I

  • System recovery disks do not work.

    I have a HP G62 339WM Notebook PC with Windows 7 Home Premium 64-bit.  I bought by mail, system recovery discs and they do not work.   And my HP Support Assistant displays "an error has occurred" and end not updates. The Troubleshooting Guide for the

  • Contacts of sort of blackBerry Smartphones

    I prefer my contacts to be sorted by last name on my BB - the same as on my laptop.   How can I change my preferences of BB? Thanks in advance

  • Windows 7 Pro - WAU is missing from the start menu

    Hello. Thanks in advance for your help. I have four computers with Windows 7 Pro. None of them are in a domain, and the users are administrators with disabled UAC. A computer that I am wanting to upgrade to Ultimate does not show the "Windows Anytime

  • Themes for prem pro

    I recently saw final cut pro and they had an option to use themes for a video piece.This feature is just what I want to achieve a recent project.is there something like this for the Prime Minister?