Ranking of Consecutive non-increasing values in a column

Hi friends
I have a table with numbers like this in a column
sr no.        value
1               17
2                0
3                0
4              38
5              32
6              24
7              12
8              51
9              42
10              1
11              1
12              0
13              0
14              1
15              1
so on....I want to find out consecutive non-increasing sequences of value (2nd column) order by sr. no (first column) in ascending order.
For example, in the 2nd column, 17 is followed by 0 and 0 and then 38 so it means 3 consecutive values (i.e starting from 17 are 0 and 0) are non-increasing and they are ranked by '1' in my desired in third column as shown below. similarly, the 2nd non-increasing sequence starts with 38,32,24 and 12 and this is ranked as '2' in the third column. same is the case with rank '3' for the third non increasing sequence. so bascially i want the third column with "ranks" starting and ending as per above logic. i tried using LEAD function but doesn't get what I want. I need the shortest possible query to get that third column since i have other columns in the original table in a multiple group by query.
my desired output is:
sr no.        value              Rank
1               17                 1
2                0                  1
3                0                  1
4              38                  2
5              32                  2
6              24                  2
7              12                  2
8              51                  3
9              42                  3
10              1                  3
11              1                  3
12              0                  3
13              0                  3
14              1                  4
15              1                  4
.                  Hope I explained the question clearly and hoping to get answer soonest.
regards
Hamza

with sample_table as (
                      select 1 sr_no,17 val from dual union all
                      select 2,0 from dual union all
                      select 3,0 from dual union all
                      select 4,38 from dual union all
                      select 5,32 from dual union all
                      select 6,24 from dual union all
                      select 7,12 from dual union all
                      select 8,51 from dual union all
                      select 9,42 from dual union all
                      select 10,1 from dual union all
                      select 11,1 from dual union all
                      select 12,0 from dual union all
                      select 13,0 from dual union all
                      select 14,1 from dual union all
                      select 15,1 from dual
               t1 as (
                      select  sr_no,
                              val,
                              case
                                when lag(val) over(order by sr_no) >= val then 0
                                else 1
                              end start_of_group
                        from  sample_table
select  sr_no,
        val,
        sum(start_of_group) over(order by sr_no) rank
  from  t1
  order by sr_no
     SR_NO        VAL       RANK
         1         17          1
         2          0          1
         3          0          1
         4         38          2
         5         32          2
         6         24          2
         7         12          2
         8         51          3
         9         42          3
        10          1          3
        11          1          3
     SR_NO        VAL       RANK
        12          0          3
        13          0          3
        14          1          4
        15          1          4
15 rows selected.
SQL> SY.

Similar Messages

  • Query only non numeric values in a column

    How to query only non numeric values in a cloumn.
    For example:
    Table1 has a column1(col1)
    Values:
    Row Value
    1 27376
    2 47D99
    3 83039
    4 DKFI*
    5 3J6
    Query should retrieve only rows(2,4,5).
    Thanks! for help
    Murali

    Version 2(PL/SQL) above is not clear enough, It can be tuned to the following:
    -- Create a function
    Create or replace function IsVARCHAR(pCol VARCHAR2) return VARCHAR2
    AS
    vNumber NUMBER := 0;
    begin
      vNumber := to_number(pCol);
      RETURN NULL;
    Exception
      When Others Then
        RETURN pCol;
    End;
    -- To See VARCHAR values (alpha-numeric) only!
    SELECT col1 FROM tab1
    WHERE IsVARCHAR(col1) IS NOT NULL;
    -- To See NUMBER values only!
    SELECT col1 FROM tab1
    WHERE IsVARCHAR(col1) IS NULL;Versatility here with PL/SQL, but I personally like SQL versions.
    Thx,
    SriDHAR

  • Retreive non-Null values

    Hi everybody
    How to retreive the values those are not Null from a table??
    I mean I want to display non-Null values from a column or set of columns(if possible)??
    Thanks in advance

    But I don't have any criteria ... But you have criteria - namely to retrieve not null values!
    Maybe you need to be more clear (with sample in- and output) of what you'd actually like to achieve.

  • Non cumulative with non cumulative value change

    hi,
    can any one tell the concept of non cumulative with non cumulative value change with an example with numbers,i am bit confused .
    like we have for non *** inflow and outflow- stocks inflow and outflow so non *** is based on inflow and inflow.
    in the same way any example for above concept

    Hi Venkat,
    If I under stand your question correctly you wish to have an example of where non cumulative values are used and you have given the value of stock? If so here is an example with figures
    So you would do an initial load loading the opening balances of Stock.
    Say material number 12345 = 100 units
    After that, only movements will be posted so Stock will either increase or decrease depending on what image is posted via the change log.
    So there will be a purchase of material 12345 for 50 units so now the balance of material is 150.
    But then you could use or sell 70 units of material 12345 so you stock value would be 80 units
    I hope this makes sense and this is an example that you are after if not please let me know and I'm happy to help
    Regards
    Ben
    PS assign points if useful

  • Invalid or Non-Increasing CFBundleVersion

    Hi,
    when updating the apps with the 31.3 build, the Apple Application loader shows the following warning on transfer:
    Invalid or Non-Increasing CFBundleVersion - The value specified in the bundle's Info.plist file for the key CFBundleVersion must be a string consisting of any number of dot-separated components, where each component is composed only of the digits 0 through 9. For example, any of the following are syntactically valid values for CFBundleVersion: "1.0", "4.2.1", "5545.12", "1.4.0.0.5"; whereas the following are all syntactically invalid: "GX5", "3.4.2b6", "2.6GM", "1.0 (Gold)", "-3.6". Additionally, each updated version of the same application must have a CFBundleVersion that increases relative to that of the previous version that was actually made available for sale on the iTunes Store. For example, if a previously-available version had a CFBundleVersion of "1.4", then any of the following would be acceptable as the next update: "1.4.0.0.0.0.5", "1.4.1", "1.4.332", "1.5"; but all of the following (though syntactically valid) would be unacceptable: "1.4", "1.3", "1.3.99999", "0.9". For more information about the CFBundleVersion key and the Info.plist file, see Apple's Runtime Configuration Guidelines at http://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPRuntimeConfig/ind ex.html
    After you’ve corrected the issues, you can use Xcode or Application Loader to upload a new binary to iTunes Connect.
    –Yves

    I got these email:
    Dear developer,
    We have discovered one or more issues with your recent delivery for "Report on the Energy Sector in Slovenia for 2013". Your delivery was successful, but you may wish to correct the following issues in your next delivery:
    Invalid or Non-Increasing CFBundleVersion - The value specified in the bundle's Info.plist file for the key CFBundleVersion must be a string consisting of any number of dot-separated components, where each component is composed only of the digits 0 through 9. For example, any of the following are syntactically valid values for CFBundleVersion: "1.0", "4.2.1", "5545.12", "1.4.0.0.5"; whereas the following are all syntactically invalid: "GX5", "3.4.2b6", "2.6GM", "1.0 (Gold)", "-3.6". Additionally, each updated version of the same application must have a CFBundleVersion that increases relative to that of the previous version that was actually made available for sale on the iTunes Store. For example, if a previously-available version had a CFBundleVersion of "1.4", then any of the following would be acceptable as the next update: "1.4.0.0.0.0.5", "1.4.1", "1.4.332", "1.5"; but all of the following (though syntactically valid) would be unacceptable: "1.4", "1.3", "1.3.99999", "0.9". For more information about the CFBundleVersion key and the Info.plist file, see Apple's Runtime Configuration Guidelines at http://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPRuntimeConfig/ind ex.html
    After you’ve corrected the issues, you can use Xcode or Application Loader to upload a new binary to iTunes Connect.
    Regards,
    The App Store team
    But afterwards I got another email from Apple which tells me that "The status for the following app has changed to Waiting For Review."
    So can I ignore email with the warning?
    Thx,
    Davorin

  • Ranking over consecutive dates

    Hi guys,
    I have been struggling with this for some days already and I have tried to implement different solutions I was able to get from searching the internet, and applying some approeaches learned from this forum on similar questions, but maybe if I put que question here someone knows exactly the best way to handle it:
    So I have a table like this:
    with payments as
    select '1' as ID, '20130331' as DateR, 'Not_paid' as Status from dual
    union
    select '1' as ID, '20130430' as DateR, 'Paid' as Status from dual
    union
    select '1' as ID, '20130531' as DateR, 'Not_paid' as Status from dual
    union
    select '2' as ID, '20130331' as DateR, 'Not_paid' as Status from dual
    union
    select '2' as ID, '20130430' as DateR, 'Not_paid' as Status from dual
    union
    select '3' as ID, '20130331' as DateR, 'Paid' as Status from dual
    union
    select '3' as ID, '20130430' as DateR, 'Paid' as Status from dual
    union
    select '3' as ID, '20130531' as DateR, 'Paid' as Status from dual
    And I am trying to get the amount of the current consecutive non-payments from a user. Now, it starts to count everytime the previous payments was Paid or it´s the first payment.
    I have tried to get through dense rank, giving me this as output:
    select ID, dater, status, dense_rank() over (partition by ID, status order by dater asc) rnk from payments
    But I need to get something like this:
    ID DATER STATUS RNK
    1   20130331  Not_paid  1
    1   20130430  Paid  1
    1   20130531  Not_Paid  1
    2   20130331  Not_paid  1
    2   20130430  Not_paid  2
    3   20130331  Paid  1
    3   20130430  Paid  2
    3   20130531  Paid  3
    Such that if I want to get the max(rank) to check how many non-payments a user currently has I get that ID has 1 unpayment, ID 2 two consecutive unpayments, and ID 3 has 0 unpayments. This is because on the fourth consecutive non-payment I have to consider the user as churned.

    Hi,
    Here's one way:
    WITH got_grp_num AS
        SELECT  p.*
        ,      ROW_NUMBER () OVER ( PARTITION BY  id
                                    ORDER BY      dater
             - ROW_NUMBER () OVER ( PARTITION BY  id, status
                                    ORDER BY      dater
                                  )   AS grp_num
        FROM    payments  p
    SELECT    id, dater, status
    ,         ROW_NUMBER () OVER ( PARTITION BY  id, status, grp_num
                                   ORDER BY      dater
                                 )   AS rnk
    FROM      got_grp_num
    ORDER BY  id, dater
    For an explanation of the Fixed Difference technique used here, see
    https://forums.oracle.com/forums/thread.jspa?threadID=2302781 and/or
    https://forums.oracle.com/forums/thread.jspa?threadID=2303591
    By the way, storing date information in a sting column is simply asking for trouble.  Use a DATE column instead.

  • Non numeric value in numeric field giving error

    Hi All
    I am using BAPI for creating sales order. If user is giving non numeric value in Quantity field it is giving error. Because quantity field data type is Double.
    Please Help.
    Thanks
    Raktim

    Hi Banerjee,
                 Create a String/int/long Context variable and point it to UI Input element.Do the validation  for correct input value. once the validation is succesful assign that value to RFC BigDecimal variable by Explicit casting.
    Hope this might solve your problem .
    Thanks
    Madhan

  • The InfoCube contains non-cumulative values

    Hi,
    While creating multicube for inventory on two cubes its askin the below "The InfoCube contains non-cumulative values. A validity table is created for these non-cumulative values, in which the time interval is stored, for which the non-cumulative values are valid.
    The validity table automatically contains the "most detailed" of the selected time characteristics (if such a one does not exist, it must be defined by the user, meaning transfered into the InfoCube)", what is that and how to solve this,
    Please through some light on this its urgent.
    Chandan

    Hi,
    Your multi cube is probably based on the infociune 0IC_C03 containing non cumulative key figures taht's why you get this message.
    You generaly don't have to maintain validity area unless you are in a special configuration (for exemple loading data from two source systems).
    UThe following link should give more information about validity area with non cumulative :
    [http://help.sap.com/saphelp_nw04/helpdata/en/02/9a6a1c244411d5b2e30050da4c74dc/frameset.htm|http://help.sap.com/saphelp_nw04/helpdata/en/02/9a6a1c244411d5b2e30050da4c74dc/frameset.htm]
    Hope this helps.
    Cyril

  • Maintaining non-cumulative values in Mlti provider

    Can we maintain non ucmulative values inteh multi ptovider   Extras - > Maintain non cumulative values section.
    I created few new cubes which has non cumulative keyfigures . In the cube I made 0CAL DAY as reference characteristic and selected  Company code (0COMP_CODE) and Posting date in the document (0PSTNG_DATE) as characteristics of validity table for non-cumulatives.
    Now I inlcude the new cubes and identified the non cumulative key figures in the multi provider.
    Now here also do I need to   make 0CAL DAY as reference characteristic and selected  Company code (0COMP_CODE) and Posting date in the document (0PSTNG_DATE) as characteristics of validity table for non-cumulatives.I did not find an option in Extras - > Maintain non cumulative values in multi provider. CAn we maintain non cumulatives in MP ?

    Hello,
    You dont need to maintain it at the MP level also.
    Non-cumulative parameters are manitained only at the cube level.This was the case in 3.x so it should be the same in 7.0 also.
    Regards
    Ajeet

  • "initial non-cumulative for non-cumulative values"  is not available in DTP (0AFMM_C02)

    Hi Experts,
    We are working for BI implementation for AFS Industry,
    when we are working on AFS specific inventory cube 0AFMM_C02 , we are facing stock mismatch problem
    for AFS Stock initialization we are using the data source 2LIS_AF_STOCK_INITALIZATION instead of 2LIS_03_BX, this data source is specificly designed for AFS
    when we are extracting the data using 2LIS_AF_STOCK_INITALIZATION for stock initialization and
    2LIS_03_BF data source to load the Moments.
    we compressed cube with Marker update for 2LIS_AF_STOCK_INITALIZATION data load(by deselecting the No marker update check box)
    we compressed cube with No Marker update for 2LIS_03_BF historical data load(by selecting the No marker update check box)
    we compressed cube with Marker update for 2LIS_03_BF Delta data load(by deselecting the No marker update check box)
    Now we are facing stock mistach problem, we found reason for this
    "initial non-cumulative for non-cumulative values" option is not available in DTP only Delta & Full options are available
    and infopackage of  2LIS_AF_STOCK_INITALIZATION data source also has "Full update" instead of "Generate Intial Status"
    Please let us know how can we get the "initial non-cumulative for non-cumulative values" option in the DTP level.
    Regards,
    Chandra

    Hi Chandrakumar,
    We are facing the same problem, how do you solve it?
    Regards,

  • Non-cumulative values

    HI All,
    when I run a query of a non-cumulative infocube,there's always a "initial record"  which actually doesn't exist in the fact table. Documents say "This entry does not remain physically in  the table, but it is available for rebuilding the non-cumulative values". So where exactly is the initial value stored ?
    Thanks
    han.

    Hi,
    What is teh DataSource and InfoCube?
    If you are talking about 0IC_C03, please see the steps.
    Treatment of historical full loads with Inventory cube
    Setting up material movement/inventory with limit locking time
    See about  Non-Cumulatives 
    http://help.sap.com/saphelp_nw2004s/helpdata/en/8f/da1640dc88e769e10000000a155106/content.htm
    Thanks
    Reddy

  • Inventory Management (Non-cumulative values)

    Dear experts,
    I want to extract inventory data from 2LIS_03_BF.
    How do I have to configure the Key figures; for example: 0VALSTCKQTY. Is there a need to use Non-cumulative value with in- and outflow as in Content.
    Which other possibilities exist?
    After InfoObject config. - what are the exact next steps?
    Do I load data from the 3 DataSources 2LIS_03_BX, 2LIS_03_BF and 2LIS_03_UM into one DSO first and then into one cube or do I have to split?
    I dont want to use the BC data flow.
    Thanks for your advice.
    Patrick

    hi,
    Please search the Forum for this, this has been discussed many times.
    regards,
    Arvind.

  • Updating a DB table with only non-empty values of a work area

    Hi everybody,
    Is that possible in ABAP to update a table in the database with a work area, but only with non-empty values of this work area?
    Example:
    data: ls_custom type ZCUSTOMERS_0.
    ls_custom-CUSTOMER = '20'.
    ls_custom-LASTNAME = 'MyName'.
    ls_custom-FIRSTNAME = ' '.
    ls_custom-CURRENCY = ' '.
    update ZCUSTOMERS_0 from ls_custom.  *" I want that the update clause don't do the update with FIRSTNAME  and CURRENCY fields because they have empty values*
    If it's possible, how to do it?
    Thanks & regards,
    Abdel

    Total Questions:  81 (66 unresolved)
    Hi,
    To my understanding you mean if the database table has values
    customer         20
    lastname          somename
    firstname         firstname
    currency          INR
    so now after this
    data: ls_custom type ZCUSTOMERS_0.
    ls_custom-CUSTOMER = '20'.
    ls_custom-LASTNAME = 'MyName'.
    ls_custom-FIRSTNAME = ' '.
    ls_custom-CURRENCY = ' '.
    update ZCUSTOMERS_0 from ls_custom.
    you want the result as
    customer         20
    lastname          Myname
    firstname         firstname
    currency          INR
    Is it so? Then Normal update
    data: ls_custom type ZCUSTOMERS_0.
    ls_custom-CUSTOMER = '20'.
    ls_custom-LASTNAME = 'MyName'.
    update ZCUSTOMERS_0 from ls_custom.
    would do that.
    Thanks,
    Sri.

  • How to check non-numeric value in a field

    Hi all,
    I have a field 'MVALUE'. HOw can I check if I have a non-numeric value in my field. Let us say if I have a value '<25' in this field. How can I check if the value in this field is non-numeric. The field MVALUE is of CHAR datatype.
    Please help. Waiting.........

    Might have to add a space in the string...
    if not mvalue co ' 0123456789'.
    * error
    endif.
    if you allow decimals and commas...
    if not mvalue co ' .,0123456789'.
    * error
    endif.

  • Non-cumulative value KF

    Hi:
    I have given the Aggregation as SUM  and the Excepiton Aggregation as Last Value for a non-cumulative KF Quantity Total Stock  for Inventory. I am using Non-cumulative value with in- Receipt Quantity Total Stock and out-flow Issue Quantity Total Stock. Then I can calculate Quantity Total Stock  in Query.
    But I have another requirement, I want to a KF to count  0Material  whose Quantity Total Stock not equal 0.  In fact, for a Non-cumulative value, the Aggregation reference char of  KF Quantity Total Stock   is 0calday, but what I want is 0Material.  How could I create such KF?
    Many thanks in Advance!
    Points will be assigned!

    Hi,
    The basic purpose of Non-cumulatives is to get the values for them depending upon the Time Characterestics alone and not on any other characterestics. As far as I know you cant use 0MATERIAL as the aggregation reference Char.

Maybe you are looking for