How to achieve using the analytical functions - please help

Oracle version: 10g
-999 means that all THE values for this key
with input_parameters as (select 10 filter_key , '10ACCC' filter_value from dual union all
select 50 filter_key ,'10ACCC0001' filter_value from dual union all
select 60 filter_key , 'PIP' filter_value from dual union all
select 70 filter_key , 'A' filter_value from dual) select * from input_parameters;


with profile_search as(
select 100 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all 
select 100 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
select 100 profile_id , 50 filter_key , '10ACCC0002' filter_value from dual union all
select 100 profile_id , 60 filter_key , '999' filter_value from dual union all
select 100 profile_id , 70 filter_key , '999' filter_value from dual union all
select 101 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
select 101 profile_id , 50 filter_key , '10ACCC001' filter_value from dual union all
select 101 profile_id , 60 filter_key , 'PIP' filter_value from dual union all
select 101 profile_id , 70 filter_key , '999' filter_value from dual union all
select 102 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
select 102 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
select 102 profile_id , 60 filter_key , 'PIP' filter_value from dual union all
select 102 profile_id , 70 filter_key , 'A' filter_value from dual)
select filter_key , wm_concat(filter_value) from profile_search group by profile_id, filter_key ;
need to identify profile that matches input parameters
---------------------------------------------------------------------------

102 is first match because it matches exactly
101 is second match because 999 can match any value
100 is third match 
70 KEY HAS THE HIGHEST WEIGHT,
A next highest weight KEY 60 and 50 next highest weight BUTTON


required results:
profile_id: 102

Published by: devarade on January 19, 2010 20:01

Published by: devarade on January 19, 2010 20:01

I guess that there is a typing error in your sample:

Select 101 profile_id, 50 filter_key, '10ACCC001' filter_value from all the double union

must be:

Select 101 profile_id, 50 filter_key, '01' filter_value from all 10ACCC00 the double union

Then:

with input_parameters as (
                          select 10 filter_key , '10ACCC' filter_value from dual union all
                          select 50 filter_key ,'10ACCC0001' filter_value from dual union all
                          select 60 filter_key , 'PIP' filter_value from dual union all
                          select 70 filter_key , 'A' filter_value from dual
                         ),
        profile_search as(
                          select 100 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
                          select 100 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
                          select 100 profile_id , 50 filter_key , '10ACCC0002' filter_value from dual union all
                          select 100 profile_id , 60 filter_key , '999' filter_value from dual union all
                          select 100 profile_id , 70 filter_key , '999' filter_value from dual union all
                          select 101 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
                          select 101 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
                          select 101 profile_id , 60 filter_key , 'PIP' filter_value from dual union all
                          select 101 profile_id , 70 filter_key , '999' filter_value from dual union all
                          select 102 profile_id , 10 filter_key , '10ACCC' filter_value from dual union all
                          select 102 profile_id , 50 filter_key , '10ACCC0001' filter_value from dual union all
                          select 102 profile_id , 60 filter_key , 'PIP' filter_value from dual union all
                          select 102 profile_id , 70 filter_key , 'A' filter_value from dual
                         )
select  profile_id,
        sum(direct_match_cnt) || ' direct matches out of ' || (select count(*) from input_parameters) match
  from  (
         select  b.profile_id,
                 b.filter_key,
                 b.filter_value,
                 sum(case when b.filter_value = a.filter_value then 1 else 0 end) direct_match_cnt
           from  input_parameters a,
                 profile_search b
           where b.filter_key = a.filter_key
             and (b.filter_value = a.filter_value or b.filter_value = '999')
           group by b.profile_id,
                    b.filter_key,
                    b.filter_value
        ) x
  group by profile_id
  having count(*) = (select count(*) from input_parameters)
  order by sum(direct_match_cnt) desc
/

PROFILE_ID MATCH
---------- ----------------------------------------
       102 4 direct matches out of 4
       101 3 direct matches out of 4
       100 2 direct matches out of 4

SQL> 

SY.

Tags: Database

Similar Questions

  • 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

  • No links to the local area network connection. But how to use the Internet again, please help establish a LAN connection.

    Original title: no local network connection

    No links to the local area network connection. But how to use the Internet again, please help establish a LAN connection.

    Hi H.mustafaakyurek,

    ·         What operating system is installed on your computer?

    You can view the following items on the creation of a network connection:

    Setting up a network home

    http://Windows.Microsoft.com/en-us/Windows7/setting-up-a-home-network

     

    Start here to set up a home network in Windows 7

    http://Windows.Microsoft.com/en-us/Windows7/start-here-to-set-up-a-home-network-in-Windows-7

     

    Setting up a wireless network

    http://Windows.Microsoft.com/en-us/Windows7/setting-up-a-wireless-network

    Also see the following articles on the connection of an Internet connection:

    What do I need to connect to the Internet?

    http://Windows.Microsoft.com/en-us/Windows7/what-do-I-need-to-connect-to-the-Internet

     

    Allows to connect to the Internet mobile broadband

    http://Windows.Microsoft.com/en-us/Windows7/use-mobile-broadband-to-connect-to-the-Internet

    Hope this information helps.

  • 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

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

  • How can I use the SUM function to calculate the number of employees in the comp. & 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

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

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

  • Since I use photoshop CC I've not found an easy way to scan by using the discreen function? help please

    Since I use photoshop CC I have not found a way to use the discreen function when you scan... help!

    discreen function?

  • How do we use the SUBSTR function in OWB

    Hello, I'm pretty new to OWB. I need to use the SUBSTR function in owb. My source table has 16 characters in length. But in my datamar,.
    the length is 14 years. I want to the substring from source to the destination. The mappings are already developed. I need to change the mapping to make sure that,
    It brings only SUBSTR (1.14) mini - DW.

    Any help is appreciated.

    Use the operator of expression between two attributes.

    OWB has already SUBSTR as a preset transformation

    Take a look at the doc below
    26.3.1 open the expression builder

    http://docs.Oracle.com/CD/E11882_01/OWB.112/e10935.PDF

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

  • By using the analytical function to sort without showing this column in the result.

    Hello

    We use the Oracle 11.2

    How to use Oracle Analytics to sort the output of a query without showing this column in the result?

    Here's my query:

    Select distinct nvl(SRC_CHR_NM,'0') | » #'|| NVL(EXPL_SRC,'0') | » #'|| NVL(DIM_NM,'0') | » #'|| NVL(DIM_CHR_NM,'0') | » #'|| NVL(DIM_CHR_ABR,'0') | » #'||

    Decode (InStr (NVL(SRC_COL_NM,'0'), 'trim ('),'1 ', Replace (NVL(SRC_COL_NM,'0'),'trim (',' trim(PRM_DTL.'), '0',' PRM_DTL.)))) » || NVL(SRC_COL_NM,'0')) AS ALLOFIT,

    DIM_NM

    from EXPL_CONFIG where SBJ_AREA_CD = 'PRMDTL. '

    I want to use analytical to sort by DIM_NM but I do not want to show. I want to just just the ALLOFIT column to show in the output.

    Something like "row_number() over (order by DIM_NM desc).

    Thank you!

    Hello

    If you SELECT SEPARATE, then you can only ORDER OF things in the SELECT clause. (Do you really need to do SELECT DISTINCT?  Often, it's just an inefficient way to remove the lines that do not need to be there at all).

    Move making the SELECT DISTINCT in a subquery and make the ORDER BY (and nothing else) in the main query.

    I hope that answers your question.

    If this isn't the case, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

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

  • 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
  • Z500 touchpad work not when you use the keyboard. Please help me please!

    Hello

    I recently bought a lenovo z500 and it's great, but I have a little problem. When I use the keyboard to play games (I use the WASD keys) the touchpad does not, which means I can't play. Help, please!

    I got it finally started working by removing the pilot of the momentum. I don't think that I will reinstall it. Thanks for your help

Maybe you are looking for