May result by analytic function that follows

Hi all

I am currently using oracle 10g.

create table
CREATE TABLE fortest
(  PROD             VARCHAR2(40 BYTE),
  prodvalues     number);
INSERT statement
insert into fortest values ('dental',10)
   insert into fortest values ('dental',4)
    insert into fortest values ('dental',13)
     insert into fortest values ('dental',3)
      insert into fortest values ('vision',2)
       insert into fortest values ('vision',11)
       insert into fortest values ('vision',33) 
        insert into fortest values ('vision',7)
I need the output as follows
prod        prodvalues <5         prodvalues >=5 and less than 10               prodvalues >=10
dental         2                                     0                                      2
vision         1                                     1                                      2
first column should give me separate prod, prodvalues5 column: should give me the number of similar prod with prodvalues less than 5, same thirdcolumn should have County of similar prod with prodvalues > = 5 and prodvalue < 10 and so on.

Please, not the names of columns of the output tables are just for reference, and I will not use them.


Thanks in advance.

Hi Bob,

You don't have to use analytical functions. Here's a solution that doesn't use analytical functions:

with temp as (select prod, case
                           when prodvalues <=5 then 1
                           else                    0
                           end  as prod5,
                           case
                           when prodvalues >=5 and prodvalues <10 then 1
                           else                    0
                           end  as prod5_10,
                           case
                           when prodvalues >= 10 then 1
                           else                    0
                           end  as prod10
                           from fortest)
                           select prod,sum(prod5) as prod5 ,  sum(prod5_10) as prod5_10 ,sum(prod10) as prod10
                           from temp
                           group by prod

Tags: Database

Similar Questions

  • get a single result with analytical functions

    SELECT delrazjn. TYPE, delrazjn. DATE, delrazjn. USER, delrazjn. The IID OF the ZKET_DR delraz, ZKET_DR_JN delrazjn
    WHERE delraz. IID = delrazjn. IID
    AND (delrazjn. TYPE = 'UP2' GOLD delrazjn. TYPE = 'An increase in 1') AND delrazjn. IID_N IS NOT NULL

    This is an example of my sql. But there is more than one result of delrazjn. IID. How can I get the first enterd in DB and ignore others, there will only be one result and no more.
    The first result came in, that I can see for delrazjn. DATE.

    I try to do that with analytical functions, but without success.

    You're right, I told you that I can't test the code.

    I hope this works now:

    SELECT delrazjn.TYPE, delrazjn.DATE, delrazjn.USER, delrazjn.IID
    FROM ZKET_DR delraz, ZKET_DR_JN delrazjn
    WHERE delraz.IID = delrazjn.IID
    AND (delrazjn.TYPE = 'UP2' OR delrazjn.TYPE = 'UP1') AND delrazjn.IID_N IS NOT NULL
    and delrazjn.date=(select min(d.date) from ZKET_DR_JN d where d.type=delrazjn.type and d.user=delrazjn.user)
    
  • How to prioritize the query result using analytic functions

    Hello

    Published by: prakash on May 20, 2013 01:42

    Use ROW_NUMBER

    SQL> select PRVDR_LCTN_X_SPCLTY_SID,PRVDR_LCTN_IID,PRVDR_TYPE_X_SPCLTY_SID,STATUS_CID
      2  from
      3  (
      4    select t.*,
      5      row_number() over(partition by PRVDR_TYPE_X_SPCLTY_SID
      6                        order by STATUS_CID) rn
      7    from your_table t
      8  )
      9  where rn = 1;
    
    PRVDR_LCTN_X_SPCLTY_SID PRVDR_LCTN_IID PRVDR_TYPE_X_SPCLTY_SID STATUS_CID
    ----------------------- -------------- ----------------------- ----------
                   75292110       10153920                75004770          1
                   75291888       10153920                75004884          2
                   75292112       10153920                75004916          1
                   75292117       10153920                75004974          1
    
  • Help me on the analytic function

    Hello

    I use oracle version
    SQL> select * From v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    PL/SQL Release 9.2.0.8.0 - Production
    CORE    9.2.0.8.0       Production
    TNS for Solaris: Version 9.2.0.8.0 - Production
    NLSRTL Version 9.2.0.8.0 - Production
    I have a following tables
    CREATE TABLE emp_info(emp_id number,ename varchar2(10),chk_date date);
    
    CREATE TABLE emp_month(emp_id number,emp_month_date date,chk_amt number(10,2));
    
    insert into emp_info VALUES (101,'PAUL',to_date('01-MAR-2009','DD-MON-YYYY'));
    insert into emp_info VALUES (102,'JOHN',to_date('01-APR-2009','DD-MON-YYYY'));
    insert into emp_info VALUES (103,'KRIS',to_date('01-MAY-2009','DD-MON-YYYY'));
    
    
    insert into emp_month values (101,'01-DEC-2008',1432);
    insert into emp_month values (101,'01-JAN-2009',1412);
    insert into emp_month values (101,'01-FEB-2009',1632);
    insert into emp_month values (101,'01-MAR-2009',1672);
    --
    insert into emp_month values (102,'01-DEC-2008',2678);
    insert into emp_month values (102,'01-JAN-2009',2786);
    insert into emp_month values (102,'01-FEB-2009',2883);
    insert into emp_month values (102,'01-MAR-2009',2653);
    insert into emp_month values (102,'01-APR-2009',2653);
    --
    insert into emp_month values (103,'01-NOV-2008',2343);
    insert into emp_month values (103,'01-DEC-2008',2311);
    insert into emp_month values (103,'01-JAN-2009',3122);
    insert into emp_month values (103,'01-FEB-2009',3412);
    insert into emp_month values (103,'01-MAR-2009',3312);
    insert into emp_month values (103,'01-APR-2009',3315);
    insert into emp_month values (103,'01-MAY-2009',4321);
    I use following the QUERY for results. Is it possible to get these same results using ANALYTICAL functions
    or I would appreciate any solution better than this.
    Select e.emp_id,e.ename,e.chk_date,sum(chk_amt) year_amt
    from emp_month em
    ,(select emp_id,ename,chk_date
    from emp_info)e
    where e.emp_id = em.emp_id
    and em.emp_month_date between trunc(e.chk_date,'YY') AND e.chk_date
    group by e.emp_id,e.ename,e.chk_date

    user12212962 wrote:

    I use following the QUERY for results. Is it possible to get these same results using ANALYTICAL functions

    or I would appreciate any solution better than this.

    I have no idea why you need analytic function. I know: there is no need to view inline in your query:

    SQL> Select e.emp_id,e.ename,e.chk_date,sum(chk_amt) year_amt
      2  from emp_month em
      3  ,(select emp_id,ename,chk_date
      4  from emp_info)e
      5  where e.emp_id = em.emp_id
      6  and em.emp_month_date between trunc(e.chk_date,'YY') AND e.chk_date
      7  group by e.emp_id,e.ename,e.chk_date
      8
    SQL> /
    
        EMP_ID ENAME      CHK_DATE    YEAR_AMT
    ---------- ---------- --------- ----------
           102 JOHN       01-APR-09      10975
           101 PAUL       01-MAR-09       4716
           103 KRIS       01-MAY-09      17482
    
    SQL> Select e.emp_id,e.ename,e.chk_date,sum(chk_amt) year_amt
      2  from emp_month em,
      3       emp_info e
      4  where e.emp_id = em.emp_id
      5  and em.emp_month_date between trunc(e.chk_date,'YY') AND e.chk_date
      6  group by e.emp_id,e.ename,e.chk_date
      7  /
    
        EMP_ID ENAME      CHK_DATE    YEAR_AMT
    ---------- ---------- --------- ----------
           102 JOHN       01-APR-09      10975
           101 PAUL       01-MAR-09       4716
           103 KRIS       01-MAY-09      17482
    
    SQL> 
    

    SY.

  • Deputy of analytical functions

    Hi all

    I'm writing a query without using the analytical functions.
    Analytical func using,.
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE     11.2.0.2.0     Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    
    SELECT id, sal, rank() OVER (PARTITION BY ID ORDER BY SAL) rnk FROM 
    (SELECT 10 AS id, 100 AS sal FROM DUAL
        UNION ALL
        SELECT 10, 300 FROM DUAL
        UNION ALL
        SELECT 10, 400 FROM DUAL
        UNION ALL
        SELECT 20, 200 FROM DUAL
        UNION ALL
        SELECT 20, 200 FROM DUAL
        UNION ALL
        SELECT 20, 300 FROM DUAL
        UNION ALL
        SELECT 30, 100 FROM DUAL
        UNION ALL
        SELECT 40, 100 FROM DUAL
        UNION ALL
        SELECT 40, 200 FROM DUAL
        )
    Expected results. I want that these results without analytical functions.
    10     100     1
    10     300     2
    10     400     3
    20     200     1
    20     200     1
    20     300     3
    30     100     1
    40     100     1
    40     200     2

    Hello

    SamFisher wrote:
    Hi all

    I'm writing a query without using the analytical functions.

    Why? What is the problem with the analytical functions? You have Oracle 11.2. Use it. Do not act as you have Oracle 8.0.

    One way to do that is a scalar subquery:

    SELECT    id
    ,       sal
    ,       (
              SELECT  1 + COUNT (*)
              FROM    table_x
              WHERE   id          = x.id
              AND     sal     < x.sal
           )     AS rnk
    FROM      table_x  x
    ORDER BY  id
    ,            rnk
    ;
    

    But it is extremely inefficient. This is an example of textbood (perhaps literally) why RANK is so useful.

  • How to use Group by in the analytic function

    I need to write the Department that has the minimum wage in a row. She must be with analytical function, but I have problem in group by. I can't use min() without group by.

    Select * from (min (sal) select min_salary, deptno, RANK() ON RN (ORDER BY sal CSA, CSA rownum) of the Group of emp by deptno) < 20 WHERE RN order by deptno;

    Published by: senza on 6.11.2009 16:09

    Hello

    senza wrote:
    I need to write the Department that has the minimum wage in a row. She must be with analytic function

    Therefore with an analytic function? Looks like it is a duty.

    The best way to get these results is with an aggregate, not analysis, function:

    SELECT      MIN (deptno) KEEP (DENSE_RANK FIRST ORDER BY sal)     AS dept_with_lowest_sal
    FROM      scott.emp
    ;
    

    Note that you do not need a subquery.
    This can be modififed if, for example, you want the lowest Department with the sal for each job.

    But if your mission is to use an analytical function, that's what you have to do.

    but I have problem in group by. I can't use min() without group by.

    Of course, you can use MIN without GROUP BY. Almost all of the aggregate (including MIN) functions have analytical equivalents.
    However, in this issue, you don't need to. The best analytical approach RANK only, not use MIN. If you ORDER BY sal, the lines with rank = 1 will have the minimum wage.

    Select * from (min (sal) select min_salary, deptno, RANK() ON RN (ORDER BY sal CSA, CSA rownum) of the Group of emp by deptno) WHERE the RN< 20="" order="" by="">

    Try to select plain old sal instead of MIN (sal) and get reid of the GROUP BY clause.

    Add ROWNUM in the ORDER BY clause is to make RANK return the same result as ROW_NUMBER, every time that it is a tie for the sal, the output will still be distinct numbers. which line gets the lower number will be quite arbitrary, and not necessarily the same every time you run the query. For example, MARTIN and WARD have exactly the same salary, 1250. The query you posted would assign rn = 4 to one of them and rn = 5 to another. Who gets 4? It's a toss-up. It could be MARTIN the first time you try, and WARD the next. (In fact, in a very small table like scott.emp, it probably will be consistent, but always arbitrary.) If this is what you want, it would be clearer and simpler just to use ROW_NUMEBR instead of RANK.

  • Try to use a function of Group on an analytic function

    Hello

    We use the Oracle 11.1.

    I have an analytic function that gives me the DENSE_RANK of lines groups. I would like to return the highest value of each group.

    The function looks like:
    DENSE_RANK( ) OVER (PARTITION BY METRIC ORDER BY sum(AEROBIC_EXERCISE_P1), COACHID)
    When I try to use:
    MAX(DENSE_RANK( ) OVER (PARTITION BY METRIC ORDER BY sum(AEROBIC_EXERCISE_P1), COACHID))
    I have get and error
    ORA-30483: window  functions are not allowed here
    Is it possible that I can do this?

    Hello

    Sorry, my mistake. You do not have an ORDER BY clause analytic it.

    COUNT (DISTINCT SUM (aerobic_exercise_p1)) OVER (PARTITION BY  metric)
    

    If you would post CREATE TABLE and INSERT statements, then I could test it.

  • Using the analytical function.

    Hello

    I have this scenario.
    with t as 
    (
    select 21009 item_id,9 primary_available,450 max_qty,100 bulk_available,12122 bulk_locator_id 
    from dual union all
    select 21009 item_id,9 primary_available,450 max_qty,2775 bulk_available,8704 bulk_locator_id 
    from dual union all
    select 21009 item_id,9 primary_available,450 max_qty,524 bulk_available,15614 bulk_locator_id 
    from dual union all
    select 21009 item_id,9 primary_available,450 max_qty,3300 bulk_available,15654 bulk_locator_id
    from dual)
    select  t.* from t;
    We have two locations for a given item_id. Primary and in bulk.

    I'm trying to get a select statement out of this point of view, where I will be restock the primary AMOUNT of sites in bulk, BUT the smaller bulk first. Once she gets up, I shouldn't take more product.

    There is an analytic function that would do this?

    That's the max I could come up with.
    with t as 
    (
    select 21009 item_id,9 primary_available,450 max_qty,100 bulk_available,12122 bulk_locator_id 
    from dual union all
    select 21009 item_id,9 primary_available,450 max_qty,2775 bulk_available,8704 bulk_locator_id 
    from dual union all
    select 21009 item_id,9 primary_available,450 max_qty,524 bulk_available,15614 bulk_locator_id 
    from dual union all
    select 21009 item_id,9 primary_available,450 max_qty,3300 bulk_available,15654 bulk_locator_id
    from dual)
    select  t.*, max_qty -
                   (primary_available + SUM(bulk_available)
                    over(PARTITION BY item_id ORDER BY bulk_available)) replen_this_much 
                    from t;
    So, in this scenario, I want to replen bulk_locator_id 100 ' 12122 'and ' 15614 bulk_locator_id 341'. That's all. ZERO of the other rentals (bulk_locator_id). If the question is not clear, please let me know.

    Published by: RPuttagunta on September 11, 2009 16:23

    Hello

    Thanks for posting the sample data.
    It would be useful that you also posted the output you want. Is this?

    .                                 BULK_         REPLEN_
    ITEM_ PRIMARY_   MAX_  BULK_      LOCATOR_        THIS_
    ID    AVAILABLE  QTY   AVAILABLE  ID               MUCH
    ----- ---------- ----- ---------- ---------- ----------
    21009 9          450   100        12122             100
    21009 9          450   524        15614             341
    21009 9          450   2775       8704                0
    21009 9          450   3300       15654               0
    

    If so, you can get to this:

    SELECT       t.*
    ,       GREATEST ( 0
                 , LEAST ( TO_NUMBER (bulk_available)
                         , TO_NUMBER (max_qty)
                        - ( TO_NUMBER (primary_available)
                          + NVL ( SUM (TO_NUMBER (bulk_available))
                                  OVER ( PARTITION BY  item_id
                                         ORDER BY      TO_NUMBER (bulk_available)
                                   ROWS BETWEEN  UNBOUNDED PRECEDING
                                     AND      1           PRECEDING
                                 )
                             , 0
                             )
                          )
                      )
                 ) AS replen_this_much
    FROM       t
    ORDER BY  item_id
    ,            TO_NUMBER (bulk_available)
    ;
    

    You should really store your numbers in NUMBER of columns.

    You essentially posted all what you need analytical functions. The problem was just wrapping this analytical function (or something very close to it) and LESS and more GRAND, so that the replen_this_much column is always between 0 and TO_NUMBER (bulk_available).

  • function that limits the result?

    Hello, I am trying to write a calculation that CAP the deduction lead after reaching a certain number, in this case $50. For example:

    -Rate of pay is $25 / hour and annualization is 2080

    .0125 * ((Pay_Rate * Annual_Hours) / 26) = $25 deduction

    -Rate of pay is $50 / hour and annualization is 2080

    .0125 * ((Pay_Rate * Annual_Hours) / 26) = $50 deduction

    -Rate of pay is $75 / hour and annualization is 2080

    .0125 * ((Pay_Rate * Annual_Hours) / 26) = deduction of50 $

    Is there a 'Limit' function that will work in this formula?

    Thanks for your help,

    Chris

    Hello Chris,

    If I understand correctly you want the function LESS.

    LESS (n1, n2 [,...] *) = smaller of numbers n1, n2,...
    Thus, for example:

    SELECT LESS (Pay_Rate * Annual_Hours / 2080)

    50

    )

    ...

    give your calculation if less than 50 and 50 otherwise
    (I rewrote your calculation is equivalent but deleting the unnecessary parentheses and grouping "* 0.0125" and "/ 26" ")

    (Note: the "opposed" LESS is MORE)

    HTH,

    Bruno Vroman.

  • How to define the condition in the analytic function

    Oracle 10g version

    Hi all

    I have the following data samples:

    Examples of data

    WITH DATA AS

    (

    SELECT 100 case_id, next_date, to_date('01-feb-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-jan-2015','dd-mon-yyyy')

    SELECT 100 case_id, next_date, to_date('01-mar-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-feb-2015','dd-mon-yyyy')

    SELECT 100 case_id, next_date, to_date('01-apr-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-may-2015','dd-mon-yyyy')

    SELECT 100 case_id, to_date('01-jun-2015','dd-mon-yyyy') next_date, to_date('01-apr-2015','dd-mon-yyyy') crt_date FROM dual

    )

    SELECT wagneur, MIN (next_date) OVER (PARTITION BY case_id) min_dt_analytical

    ,(

    SELECT MIN (next_date) DATA dd

    WHERE dd.case_id = d.case_id

    AND dd.next_date > crt_date

    ) min_dt_sub_query

    DATA d

    ;

    My question is that I get min_dt_sub_query using sub query but I want to use the analytical instead of query sub function so I created min_dt_analytical column, but I do not have how to give the condition that is AND dd.next_date > crt_date analytical so that I can get the same result as min_dt_sub_query data accordingly. Thanks in advance

    Concerning

    MIT

    Do not know if I understood your needs... but... something like that?

    WITH DATA AS (SELECT 100 case_id, next_date, to_date('01-feb-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-jan-2015','dd-mon-yyyy')

    SELECT the 100 case_id, next_date, to_date('01-mar-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-feb-2015','dd-mon-yyyy')

    SELECT the 100 case_id, next_date, to_date('01-apr-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-may-2015','dd-mon-yyyy')

    SELECT 100 case_id, next_date, to_date('01-apr-2015','dd-mon-yyyy') double crt_date to_date('01-jun-2015','dd-mon-yyyy'))

    SELECT d.

    MIN (next_date) OVER (PARTITION BY case_id) min_dt_analytical

    MIN(CASE WHEN next_date > crt_date THEN next_date ELSE NULL END) OVER (PARTITION BY case_id) AS min_dt_sub_query2

    DATA d;

    HTH

  • [8i] can I use an analytical function, or do I need a subquery?

    Hi all...

    This should be a quick. I hope I can solve my problem with an analytic function, but I don't know if it's possible. Can I use a subquery if I have to, but I'd really rather not.

    Here is a very simple version of what I'm trying to do:
    CREATE TABLE     test123
    (     field1          VARCHAR2(10)
    ,     field2          VARCHAR2(10)
    ,     my_date          DATE
    );
    
    INSERT INTO     test123
    VALUES     ('value1', 'a',TO_DATE('12/31/1900','mm/dd/yyyy'));
    INSERT INTO     test123
    VALUES     ('value1', 'b',TO_DATE('01/02/2010','mm/dd/yyyy'));
    INSERT INTO     test123
    VALUES     ('value1', 'c',TO_DATE('01/05/2010','mm/dd/yyyy'));
    
    INSERT INTO     test123
    VALUES     ('value2', 'a',TO_DATE('12/31/1900','mm/dd/yyyy'));
    INSERT INTO     test123
    VALUES     ('value2', 'b',TO_DATE('01/01/2010','mm/dd/yyyy'));
    INSERT INTO     test123
    VALUES     ('value2', 'c',TO_DATE('01/15/2010','mm/dd/yyyy'));
    I want the results:
    FIELD1     FIELD2
    --------------
    value2     a
    value2     b
    value2     c
    value1     a
    value1     b
    value1     c
    I started with the following query:
    SELECT     field1
    ,          field2
    FROM     test123
    ORDER BY     MIN(my_date)     OVER     (
                                                 PARTITION BY     field1
                                                 )                                -- removed DESC here
    ,               field2
    But the problem is the database has a date of 31 December 1900 ' as default / initial for any date field. I don't want these default values taken into account in my calculation of min. I tried to put a WHERE clause in my analytical function [WHERE my_date <>TO_DATE (' 12/31/1900 ',' mm/dd/yyyy')], but I kept getting an error message "missing right parenthesis", so it seems that you can not have a WHERE clause here... or I'm just something wrong?

    Moreover, it is a 8i database...

    Edited by: user11033437 may 20, 2010 17:16: took the 'DESC' criteria out of my order by clause. In my real application, I need DESC, but not the example.

    Hello

    A WHERE clause excludes rows in the results set. Whenever you want you can have a WHERE clause that was more limited (for example, something that would simply exclude MIN calculating values in the ORDER BY clause), then think CASE:

    SELECT       field1
    ,       field2
    FROM       test123
    ORDER BY  MIN ( CASE
                  WHEN  my_date > TO_DATE ( '12/31/1900'
                                 , 'MM/DD/YYYY'
                                 )
                  THEN  my_date
              END
               )     OVER     (PARTITION BY     field1)      DESC
    ,       field2
    ;
    

    This puts the lines for "Value1" first.
    The minimum my_date for "Value1" (after excluding the values of 1900) is later than the minimum for "Value2", so I think that you either made a mistake in the desired output, or you do not want sorted by descending order.

    As always, thanks for the display of the data of the sample and the results so clearly.

  • SQL question, perhaps with the analytical functions?

    I have a small problem:

    I have a table with:

    DAY_ID, PAGE_ORDER, SID, TIME, CONTENT.

    I want only to the rank (min) of lines with the same content when there is more than

    the one with the same content that follows.

    The data are:

    DAY PAGE_ORDER SID TIMES CONTENT

    20150825 1 4711 25.08.15 06:38:43 / body/home

    4711 2 20150825 25.08.15 06:39:10 home, aufmacher, Home, 42303938

    20150825 3 4711 25.08.15 06:39:15 welcome, aufmacher, Home, 42303938

    20150825 4 4711 25.08.15 06:39:20 home, aufmacher, Home, 42303938

    20150825 5 4711 25.08.15 06:39:24 home, aufmacher, Home, 42303938

    20150825 6 4711 25.08.15 06:39:32 home, aufmacher, Home, 42303938

    20150825 7 4711 25.08.15 06:39:39 home/aufmacher/Home/42303938

    20150825 8 4711 25.08.15 06:39:46 welcome, aufmacher, Home, 42303938

    20150825 9 4711 25.08.15 06:39:49 home, aufmacher, Home, 42303938

    4711 10 20150825 25.08.15 06:39:51 home, aufmacher, Home, 42303938

    4711 11 20150825 25.08.15 06:41:17 pol/art/2015/08/24/paris

    20150825 12 4711 25.08.15 06:42:36 / body/home

    20150825 13 4711 25.08.15 07:06:09 / body/home

    20150825 14 4711 25.08.15 07:06:36 reg/article/memo

    I want as a result:

    20150825 1 4711 25.08.15 06:38:43 / body/home

    4711 2 20150825 25.08.15 06:39:10 home, aufmacher, Home, 42303938

    4711 11 20150825 25.08.15 06:41:17 pol/art/2015/08/24/paris

    20150825 12 4711 25.08.15 06:42:36 / body/home

    20150825 14 4711 25.08.15 07:06:36 reg/article/memo

    Who knows a good way?

    Thank you very much

    It sounds like a simple solution group. You group by content and maybe a few other columns such as the day and sid. So, you want to show some value of inside this group. Several different aggregate functions to do this.

    Not tested, because of lack of tabe create and insert scripts

    select day, sid, content
            ,min(page_order) as page_order
            ,min(times) as times -- if the first page_order also has the first time
            ,min(times) keep dense_rank first (order by page_order) as times2 -- this is needed in case the first page_order is at a later time
    from yourTable
    group by day, sid, content
    

    If Solomon is right, and several identical content may exist (the example data show that). Then we can use the Tabibitosan method to create the groups.

    with step1 as (select t1.*, row_number() over (partition by day, sid, content order by page_order) rn
                         from yourTable
                         )
    select  day, sid, content
             , page_order - rn as group_number
             , min(page_order) as page_order
             , min(times) as times -- if the first page_order also has the first time
             , min(times) keep dense_rank first (order by page_order) as times2 -- this is needed in case the first page_order is at a later time
    from step1
    group by day, sid, content, page_order - rn
    order by day, sid, content, group_number;
    
  • 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.

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

  • Analytical functions, model indexes and multiple dimensions.

    I don't understand the notion of analytic functions (windowing clause) in the regulation of a model clause. I discovered an ordinary table as one-dimensional, and I can understand the concept of window, just like a line on a segment line. However with the models, there are several dimensions, so I guess that the window to become a kind of cube, instead of a line segment. But I'm not.

    For example, I have a matrix sparse 2D, with 5 values non-zero:
    select * from field
      where f is not null
    
    X     Y     F
    -----------------
    5     8     X
    6     6     X
    6     8     X
    7     7     X
    7     8     X
    I guess that the following clause of the model
    with t as(
      select *
        from field
       model
         reference old_field
           on
           (
             select * from field
           )
           dimension by (x, y)
           measures     (f)
         main new_field
           dimension by (x, y)
           measures     (cast(f as varchar2(3)) f)
           rules
           (
             f[x,y] = max(old_field.f) over (order by old_field.y range between 1 preceding and 1 following)
           ))
    select * from t
      where f is not null
    to assign for each cell up among its neighbors vertical 2. Just like
    0 0 0      0 X 0
    0 X 0  ->  X X 0
    X 0 0      X X 0
    But the real result is all NULL values.

    Hello

    with a as
    (
    select
    level L
    from
    dual
    connect by level < 4
    )
    
    select
         X
         ,Y
         ,Z
         ,X*3+Y
    
    from
         a          A1
         ,A     A2
    
    model
         dimension by ( A1.L X, A2.L Y )
         MEASURES (0 Z)
         RULES
         (
         Z[X,Y] = COUNT(Z) OVER (ORDER BY X * 3 + Y RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING)
         )
    
    X Y Z X*3+Y
    - - - -----
    1 1 2     4
    1 2 3     5
    1 3 3     6
    2 1 3     7
    2 2 3     8
    2 3 3     9
    3 1 3    10
    3 2 3    11
    3 3 2    12 
    
     9 rows selected 
    

    for x, y = 1.1, there is no previous rank if it is not counted. current line + line = 2
    for x, y = 1, 2, the previous line + line current + more rank = 3
    for x, y = 1.3 the previous line + line current + more rank = 3
    for x, y = 2, 1, the previous line + line current + more rank = 3
    ...
    for x, y = 3, 2 the previous line + line current + more rank = 3
    for x, y = 3, 3 the stored previous + current line = 2. There is no next line.

    What exectly not understand you?

    Kind regards
    Peter

Maybe you are looking for

  • iMovie; Video rendering error 60

    I am trying to share a project to My Documents in iMovie to youtube, but when I try to share the images (720 p, 60 fps) it will always fail to export and share telling me there video rendering error 60. I think it all started when I downloaded Mac OS

  • WLAN disconnect on my Satellite L300

    Very expensive! I got Toshiba Satellite L300 1 to 3 for two years now with original Windows Vista Home Premium (32 bit). My wireless has never worked. I updated my driver for my Realtek (RTL8187B wireless 802 11 b / g 54 Mbps USB 2.0 network adapter)

  • Memory or T60 video problem

    I got a T60 with win xp sp3 and on startup, I get a few scratches on the thinkpad and the winlogo. After him, the office shows no artifacts or bands and everything seems normal, except that the video driver is missing. It has the ati X 1300 card and

  • Pulse/counter of encoder data wrong servo motor

    First of all, I am very new to the use of labview.  I'm trying to complete a project, a former employee was working on that. For a quick background on what I'm working with, I use an NI DAQCard-6036E connected to a SC-2345.  SC-2345 is then connected

  • p259ng

    Hello I upgraded my HP to win 10. I also have a LG TV 671 S. I have the HP Pavilion 15 p 259 ng 15 - p259ng HP Pavilion flower sich durch following therefore Damen aus: