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

Tags: Database

Similar Questions

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

  • SQL using the analytic function


    Hi all

    I want a help in the creation of my SQL query to retrieve the data described below:

    I have a test of sample table containing data as below:

    State ID Desc

    MICHAEL 1 T1

    ACTIVE 2 T2

    T3 3 SUCCESS

    DISABLE THE T4 4

    The thing I want to do is to select all the lines with an ACTIVE status in the table but is there is no ACTIVE status, my request will give me the last line with MICHAEL status.

    I can do this in a single request by using the analytical function for example, if yes can yiu help me on the request of unpacking.

    Kind regards

    Raluce

    Something like that?

    I had to fix it.

    with testdata until)
    Select 1 id, "T1" dsc "DISABLED" status of Union double all the
    Select 2 id, 'T2' dsc, the status "ACTIVE" of all the double union
    Select id 3, "T3" dsc, the status of 'SUCCESS' of all the double union
    Select 4 id, "T4" dsc "DISABLED" status of double
    )

    Select
    ID
    dsc
    status
    of testdata
    where
    status =
    -case when (select count (*) in testdata where status = 'ACTIVE') > 0
    then 'ACTIVE '.
    Another 'DISABLED '.
    end
    and)
    ID in (select id from testdata where status = ' ACTIVE')
    or
    ID = (select max (id) in testdata when status = 'DISABLED')
    )

    STATE ID DSC

    '2' 'T2' 'ACTIVE '.

    Maybe it's more efficient

    Select
    ID
    dsc
    status
    of testdata
    where
    status =
    -case when (select count (*) in testdata where status = 'ACTIVE') > 0
    then 'ACTIVE '.
    Another 'DISABLED '.
    end
    and
    ID =)
    -case when (select count (*) in testdata where status = 'ACTIVE') > 0
    then id
    on the other
    (select max (id) in testdata when status = 'DISABLED')
    end
    )

    Post edited by: correction of chris227

    Post edited by: chris227
    extended

  • the adobe reader of adobe purchased but installed standard first pro. now, the 'pro' trial has expired and I can't use the "standard" functions

    I bought the adobe reader from adobe but installed standard first pro. now, the 'pro' trial has expired and I can't use the "standard" functions How can I solve this in order to use Adobe Standard - one that I bought?

    Hi Jodie,

    There is no standard to pro versions of Adobe Reader.

    You have downloaded the Acrobat version which is paid instead of Adobe Reader software.

    As the trial has expired, then you won't be able to use it unless you have purchased the product.

    However, you can download Adobe Reader for free using this link Adobe Acrobat Reader DC install for all versions.

    Kind regards

    Nicos

  • can I use create valude function for MSSql scalar and table.

    Hello

    (1) can I use create scalar function for MSSql and function table?
    (2) is there how many type of function defined by the user in oracle 11 g express?
    (3) and I can reture 'type' any form user defined function?


    Attract sincerely

    944768 wrote:

    the answer lies in a few cases only,

    The response illustrates the basic concept of how customers need to use cursors created using PL/SQL as a layer of abstraction - SQL and this concepts adapts to ALL cases where the customer wants to Oracle via PL/SQL cursor.

    a case is,
    If my function returns only a single value, then I can use oracle 'create function' with the return type as types predefined as a whole, varchar2 etc?
    with regard to performance.

    With regard to this performance problem? And why now suddenly change the question to want to use a function to return data type number or string? How does this relate to PL/SQL to return a cursor now?

    A function can return scalar values, not scalar. A function may return atomic values (such as a unique number, or a non-scalar list of numbers). A function can return a complex data structure consisting of scalar values, not scalar.

    However, in PL/SQL function must NOT be used to read the lines of the database to cache lines in a memory of the server PL/SQL (PGA), then back to the client.

    He does not. It does not fit. It is too bloody dangerous to the overall health of the server as such code plays silly blighters with very expensive server memory.

    A PL/SQL function can also be used as guideline, returning data via expensive PGA, but via the SQL engine instead and using its slider interface (which allows output data to be "gradual" and not to return all data with a single copy of croustilleur mass of the call stack) directly. IT IS, HOWEVER, AN EXCEPTION. There is very rarely the need to make the functions PL/SQL pipeline table - and is often victims of abuse and bad demonstrated with examples of absurd code here.

  • I bought the plan for photography and still pay each month. but I can't use photoshop only after update. and they need to join a plan. How can I do? I can only use for the trial version even I never tell months.

    I bought the plan for photography 6 months ago and still pay every month.

    but I can't use photoshop only after update. and they need to join a plan.

    How can I do?

    I can only use for the same test version that I pay every month.

    Hi yejik42305752,

    Please see the following article: https://helpx.adobe.com/creative-suite/kb/trial--1-launch.html

    Kind regards

    Tanuj

  • by using the analytical function to get the right output.

    Hello all;

    I have the following date of sample below
    create table temp_one
    (
           id number(30),   
          placeid varchar2(400),
          issuedate  date,
          person varchar2(400),
          failures number(30),
          primary key(id)
    );
    
    insert into temp_one values (1, 'NY', to_date('03/04/2011', 'MM/DD/YYYY'), 'John', 3);
    
    insert into temp_one values (2, 'NY', to_date('03/03/2011', 'MM/DD/YYYY'), 'Adam', 7);
    
    insert into temp_one values (3, 'Mexico', to_date('03/04/2011', 'MM/DD/YYYY'), 'Wendy', 3);
    
    insert into temp_one values (4, 'Mexico', to_date('03/14/2011', 'MM/DD/YYYY'), 'Gerry', 3);
    
    insert into temp_one values (5, 'Mexico', to_date('03/15/2011', 'MM/DD/YYYY'), 'Zick', 9);
    
    insert into temp_one values (6, 'London', to_date('03/16/2011', 'MM/DD/YYYY'), 'Mike', 8);
    It's the output I want
    placeid       issueperiod                               failures
    NY              02/28/2011 - 03/06/2011          10
    Mexico       02/28/2011 - 03/06/2011           3
    Mexico        03/14/2011 - 03/20/2011          12
    London        03/14/2011 - 03/20/2011          8
    Any help is appreciated. I'll post my request as soon as I can think of a good logic for this...

    Hello

    user13328581 wrote:
    ... Please note, I'm still learning how to use analytical functions.

    It doesn't matter; analytical functions will not help in this problem. The SUM aggregate function is all you need.
    But what do you need to GROUP BY? What is the value of each row of the result will represent? A placeid? Yes, each line will represent only placedid, but it will be divided further. You want a separate line of the output for each placeid and every week, then you'll want of the week and GROUP BY placeid. You don't want to GROUP BY the raw issuedate; that would put on 3 March and 4 March in separate groups. And you don't want to GROUP BY failures; This would mean that a line with 3 failures could never be in the same group in line with 9 failures.

    This becomes the output you posted from the sample data you posted:

    SELECT       placeid
    ,             TO_CHAR ( TRUNC (issuedate, 'IW')
                  , 'MM/DD/YYYY'
                ) || ' - '|| TO_CHAR ( TRUNC (issuedate, 'IW') + 6
                                             , 'MM/DD/YYY'
                               )     AS issueperiod
    ,       SUM (failures)                  AS sumfailures
    FROM        temp_one
    GROUP BY  placeid
    ,            TRUNC (issuedate, 'IW')
    ;
    

    You can use a subquery to calculate TRUNC (issuedate, 'IW') once. The code would be of about as complicated, efficiency probably will not improve substantially and the results would be the same.

  • Use of analytic functions

    Hi gurus,
    I ask someone to enlighten me on the analytical functions.
    I used the following query:
    select * from 
    (select filename,count(regexp_substr(filename,'.*era'))over(  partition by regexp_substr(filename,'.*era') ) cnt
     FROM 
    l_x12n_835_fileinfo where partitionnum=76000 and clntsysnum=76500 and radt>='01-JAN-2010')
    where cnt>1
    The sample result set is:
    FILENAME     CNT
    
    rsmedcalwa.20100105.chpwr.072.era     4
    rsmedcalwa.20100105.chpwr.072.era.1     4
    rsmedcalwa.20100105.chpwr.072.era.2     4
    rsmedcalwa.20100105.chpwr.072.era.3     4
    rsmedcalwa.20100105.chpwr.081.era     3
    rsmedcalwa.20100105.chpwr.081.era.1     3
    rsmedcalwa.20100105.chpwr.081.era.2     3
    rsmedcalwa.20100106.chpwr.088.era     3
    rsmedcalwa.20100106.chpwr.088.era.1     3
    rsmedcalwa.20100106.chpwr.088.era.2     3
    rsmedcalwa.20100108.chppr.363.era.3     4
    rsmedcalwa.20100108.chppr.363.era.1     4
    rsmedcalwa.20100108.chppr.363.era.2     4
    rsmedcalwa.20100108.chppr.363.era     4
    Now, I changed the query to:
    select * from 
    (select filename,count(regexp_substr(filename,'.*era'))over(  partition by regexp_substr(filename,'.*era') order by filename   ) cnt
     FROM 
    l_x12n_835_fileinfo where partitionnum=76000 and clntsysnum=76500 and radt>='01-JAN-2010')
    where cnt>1
    The result set has been
    FILENAME     CNT
    
    rsmedcalwa.20100105.chpwr.072.era.1     2
    rsmedcalwa.20100105.chpwr.072.era.2     3
    rsmedcalwa.20100105.chpwr.072.era.3     4
    rsmedcalwa.20100105.chpwr.081.era.1     2
    rsmedcalwa.20100105.chpwr.081.era.2     3
    rsmedcalwa.20100106.chpwr.088.era.1     2
    rsmedcalwa.20100106.chpwr.088.era.2     3
    rsmedcalwa.20100108.chppr.363.era.1     2
    rsmedcalwa.20100108.chppr.363.era.2     3
    rsmedcalwa.20100108.chppr.363.era.3     4
    rsmedcalwa.20100112.chpwr.175.era.1     2
    rsmedcalwa.20100112.chpwr.175.era.2     3
    (1) I don't understand how the addition of the order by clause changes the count. Could someone explain please?
    When I change this order by order of regexp_substr(filename,'.*era'), it gives me the correct number.

    My requirement is to check how many similar file names I.

    (2) if there are any other better elsewhere, please let me know.

    Hello

    Analytical functions still carried on in a window of the the result set, which can be smaller than the result set.
    If you have a PARTITION BY clause, the window for each row includes rows with the same values from all the PARTITION BY expressions.
    If you have an ORDER BY clause, the window includes that of a section of consecutive lines in the score, as defined by a windowing clause (in other words, LINES or KEEP them). The default value is "RANGE BETWEEN UNBOUNDED PRECEDING AND LINE CURRENT.

    In your case, if the analytical clause is:

    over(  partition by regexp_substr(filename,'.*era') )
    

    and the line you are looking at a filename = 'rsmedcalwa.20100105.chpwr.072.era.2', the window takes up the entire partition, in other words, all lines whose name includes "rsmedcalwa.20100105.chpwr.072.era". In other words, the window is identical to the partition, because theree is no ORDER BY clause.

    But if you add an ORDER BY clause:

    over(  partition by regexp_substr(filename,'.*era') order by filename   )
    

    then the window (potentially) decreases. Since there is no clause window, the default value 'RANGE BETWEEN UNBOUNDED PRECDING AND a CURRENT LINE' is used, which means that only the lines with a lower or equal to "rsmedcalwa.20100105.chpwr.072.era.2" file name (using the normal string comparison) will affect the results.

    The analytical ORDER BY clause is required for certain features (such as ROW_NUMBER) significance only in regard to certain commands. For the most part fucntions (including COUNTY), the ORDER BY clause is optional, and you do not have to use a. In this case, it seems that you do not want the effect of a smaller than the partition window, just so, do not use an ORDER byclause of Analytics for this function.

    Remember, the analytical ORDER byclause is completely independent the ORDER BY query clause. If you want the result presented in a certain order, use an ORDER BY clause at the end of the query. It will not change the results of the analytical functions.

  • How can I use the SUM function to calculate the number of employees in the comp. &amp; deptnt?

    I have two tables: employees and their departments. I'm figuring the total employees by the Department and the total employees of the entire society. I know I have to use the SUM function, but I can only calculate total employees by Department and company separately. I need to get this result:

    DEPT_NAME     DEPT_TOTAL_SALARY         COMPANY_TOTAL_SALARY
    RESEARCH                  10875                        29025
    SALES                      9400                        29025    
    ACCOUNTING                 8750                        29025      
    
    
    This is my code:
    
    SELECT department_name, SUM(salary) as total_salary
    FROM employee, department
    WHERE employee.department_id = department.department_id
    GROUP BY department_name;
    
    SELECT SUM(salary)
    FROM employee;
    
    
    
    
    
    
    Can somebody help please?
    Thank you in advance.
    Published by: user13675672 on January 30, 2011 14:29

    Published by: user13675672 on January 30, 2011 14:31

    Hello

    Something like:

    SELECT dname,
           dept_tot_sal,
           SUM (dept_tot_sal) OVER () comp_tot_sal
    FROM   (SELECT   dname,
                     SUM (sal) dept_tot_sal
            FROM     dept, emp
            WHERE    dept.deptno = emp.deptno
            GROUP BY dname);
    

    There might be a smarter way, with no re - select.

    Concerning
    Peter

    Analytical functions:
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions004.htm

  • How to achieve this using an analytic function - please help

    version 10g.
    This code works very well with my requirement. I'm tyring learn analytical functions and implement than in the query below. I tried to use row_number,
    but I could nt achieve the desired results. Please give me some ideas.

    SELECT c.tax_idntfctn_nmbr irs_number, c.legal_name irs_name,
           f.prvdr_lctn_iid
      FROM tax_entity_detail c,
           provider_detail e,
           provider_location f,
           provider_location_detail pld
     WHERE c.tax_entity_sid = e.tax_entity_sid
       AND e.prvdr_sid = f.prvdr_sid
       AND pld.prvdr_lctn_iid = f.prvdr_lctn_iid
       AND c.oprtnl_flag = 'A'
       AND c.status_cid = 2
       AND e.oprtnl_flag = 'A'
       AND e.status_cid = 2
       AND (c.from_date) =
              (SELECT MAX (c1.from_date)
                 FROM tax_entity_detail c1
                WHERE c1.tax_entity_sid = c.tax_entity_sid
                  AND c1.oprtnl_flag = 'A'
                  AND c1.status_cid = 2)
       AND (e.from_date) =
              (SELECT MAX (c1.from_date)
                 FROM provider_detail c1
                WHERE c1.prvdr_sid = e.prvdr_sid
                  AND c1.oprtnl_flag = 'A'
                  AND c1.status_cid = 2)
       AND pld.oprtnl_flag = 'A'
       AND pld.status_cid = 2
       AND (pld.from_date) =
              (SELECT MAX (a1.from_date)
                 FROM provider_location_detail a1
                WHERE a1.prvdr_lctn_iid = pld.prvdr_lctn_iid
                  AND a1.oprtnl_flag = 'A'
                  AND a1.status_cid = 2)
    Thank you

    Published by: new learner on May 24, 2010 07:53

    Published by: new learner on May 24, 2010 10:50

    Can be like that not tested...

    Select *.
    Of
    (

    SELECT c.tax_idntfctn_nmbr irs_number, c.legal_name irs_name,
    f.prvdr_lctn_iid, c.from_date as c_from_date, max (c.from_date) more (partition c.tax_entity_sid) as max_c_from_date,
    e.from_date as e_from_date, max (e.from_date) more (partition e.prvdr_sid) as max_e_from_date,
    PLD.from_date as pld_from_date, max (pld.from_date) more (pld.prvdr_lctn_iid partition) as max_pld_from_date

    OF tax_entity_detail c,.
    e provider_detail
    provider_location f,
    LDP provider_location_detail
    WHERE c.tax_entity_sid = e.tax_entity_sid
    AND e.prvdr_sid = f.prvdr_sid
    AND pld.prvdr_lctn_iid = f.prvdr_lctn_iid
    AND c.oprtnl_flag = 'A '.
    AND c.status_cid = 2
    AND e.oprtnl_flag = 'A '.
    AND e.status_cid = 2
    AND pld.oprtnl_flag = 'A '.
    AND pld.status_cid = 2

    ) X
    where c_from_date = max_c_from_date AND e_from_date = max_e_from_date AND
    pld_from_date = max_pld_from_date

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

  • How can I use the BCGTransform function to treat the 16-bit Image?

    Hi ~

    I use LabWindowsCVI8.5 and NI Vision to make the treatment of the Image. When I read the "IMAQ Vision for LabWindowsCVI Reference Manual", I found that the imaqBCGTransform function only supports 8-bit Image, while I do the BCG to turn on 16-bit image. Are there solutions to use the BCGTransform function to deal with the 16-bit Image? Or any other feature that could make the correction Gamma, contrast and brightness on the 16-bit Image?

    Thank you very much!

    because imaqBCGTransform is implemented as a lookup table, we can understand why it is limited to 8-bit images.

    Now let's take a look at the definition of each of this mandate (from the NI Vision Concepts documentation):

    -brightness: a constant added to the components red, green, and blue pixel of color over color, decoding of the process;

    -contrast: a constant multiplication factor applied to the components of the luma and chroma of a pixel of color in color to decoding process.

    -gamma correction: expand high gray-level information in an image while removing information of low level of gray.  (the chapter on lookup tables gives some examples of corrections gamma)

    now that you understand that this transformation is a simple mathematical function, simply calculate the correction for each pixel on your 16-bit images.

    I know not the exact formula used by the imaqBCGTransform function, but you should be able to approach by performing some tests on images 8 bits with the original function... or you can make your own formula... or find one on the net... or you can ask someone at home OR you give the formula...

  • Nth salary using the analytic function

    I use under function to calculate second highest with empno and deptno salary.

    Is it possible to get the same result with another query without using Assembly only analytical functions condition.using and windows function is possible to get the desired output?

    SELECT e.empno,

    e.DEPTNO,

    tmp. SAL as second_higher_salary

    FROM emp e,.

    (SELECT Empno,

    DEPTNO,

    SAL,

    DENSE_RANK() (PARTITION BY deptno ORDER of sal) AS rnk

    WCP

    ) tmp

    WHERE tmp.deptno = e.deptno

    and tmp.rnk = 2

    EMPNO DEPTNO SAL

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

    7934 10 2450

    7782 10 2450

    7839 10 2450

    7876 20 1100

    7369 20 1100

    7902 20 1100

    7788 20 1100

    7566 20 1100

    7900 30 1250

    7844 30 1250

    7654 30 1250

    7521 30 1250

    7499 30 1250

    7698 30 1250

    7900 30 1250

    7844 30 1250

    7654 30 1250

    7521 30 1250

    7499 30 1250

    7698 30 1250

    Here's my solution:

    Select empno,

    DEPTNO,

    FIRST_VALUE (sal) (PARTITION BY deptno ORDER by sal desc)

    de)

    SELECT EmpNo,

    DEPTNO,

    Decode (DENSE_RANK () OVER (PARTITION BY deptno order by sal desc), 1,-sal, sal) sal

    WCP

    )

    /

    EMPNO DEPTNO FIRST_VALUE (SAL) OVER (PARTITIONBYDEPTNOORDERBYSALDESC)

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

      7782 10 2450
      7934 10 2450
      7839 10 2450
      7566 20 2975
      7876 20 2975
      7369 20 2975
      7788 20 2975
      7902 20 2975
      7499 30 1600
      7844 30 1600
      7654 30 1600
      7521 30 1600
      7900 30 1600
      7698 30 1600
  • How can I use the Ratio_to_report function in obiee

    Hello
    I have to use the ratio_to_report function to create the report.
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions124.htm.

    This is the link that explains the use of this function. This function calculates the ratio of a value to the sum of a set of values. How can I achieve this in BI


    Please help me

    Thank you
    Angelique

    Ensure that the measure is not shaved base measure, and it is the measure of level of detail...

    need more information about your data modeling, how tables are joined and how you aggregate them...

  • I have an officejet 6600 and I can not use the copy function. any suggestions?

    I just bought an officejet 6600 and I tried to use the copy function.  Is it possible to copy a few items @ a time on the top

    HI yankee59,

    What happens if you go to your printer and select copy on the front panel? Do you get the options to copy as many copies ect...?

Maybe you are looking for