Get the next row in the set of results under certain conditions

Hello
I have a result set with a column in ascending order of the numbers. Now, I want to compare these numbers to a value. If one of the numbers exactly matches the value then all is well and I use number < = value as a condition. If the value does not match exactly I want to get the next number in the result as well. A short example

NB in resultset
41
82
123
164
205
246

To compare with value = 200, I want to have

41
82
123
164
205

as a result.

To compare with value = 164, I want to have

41
82
123
164

Thanks for any advice.
Carsten cordially

You can use analytical functions for that. There are several options, here is one.

with testdata as (select 41 num from dual union all
                  select 82  num from dual union all
                  select 123 num from dual union all
                  select 164 num from dual union all
                  select 205 num from dual union all
                  select 246 num from dual)
/* end of test data creation */
    ,resulttab as (select num, nvl(lag(num) over (order by num) ,0) next_num
                   from testdata )
select num
from resulttab
where next_num < 200 ;
NUM
---
41
82
123
164
205

...
select num
from resulttab
where next_num < 164 ;
41
82
123
164

Tags: Database

Similar Questions

  • hide the text label in the section report IR under certain conditions

    Hello
    We have a textlabel and a calculated field in a section of report to the IR 11.1.2.1. Is it possible (in a script) to hide the textlabel and field based on certain conditions, like for example, if the field computes to 'zero '?
    Thank you.

    Use a field instead of the text label. In the Expression Editor you can use the function if() {} else {}

    HTH

    Wayne

  • Get the set of results within single quotes.

    SQL>SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE='TABLE';
    
    OBJECT_NAME
    ----------------------------------------------------------------------------
    BONUS
    CHILD
    DEPT
    EMP
    EMP_DTL
    ENTRY
    How can I get this result set in single quotes as
    OBJECT_NAME
    ----------------------------------------------------------------------------
    'BONUS'
    'CHILD'
    'DEPT'
    'EMP'
    'EMP_DTL'
    'ENTRY'
    Published by: GarryB on May 12, 2009 04:07
    SQL> select ''''||ename||'''' from emp;
    
    ''''||ENAME|
    ------------
    'SMITH'
    'ALLEN'
    'WARD'
    'JONES'
    'MARTIN'
    'BLAKE'
    'CLARK'
    'SCOTT'
    'KING'
    'TURNER'
    'ADAMS'
    'JAMES'
    'FORD'
    'MILLER'
    
    14 rows selected.
    
    SQL>
    
  • Color of the text label changing under certain conditions

    Hello

    I have these labels and I would like to change the color of the text IF the text has some specific value (from an XML created by a program); for example, the default text color is red, but if the text value is 'Yes', the text color should be green.

    Any help much appreciatted, as usual...

    Thank you.

    not sure, but you might be able to get away with something like this:


    http://www.Adobe.com/2006/mxml"layout ="absolute">
       
       
           

    public void changeColor(value:String):uint
    {
    If (value is 'Yes')
    {
    Return 0x007F00;
    }
    on the other
    {
    Return 0x7F0000;
    }
           
    }
               
    ]]>
       
       
       
           
           
           
       

       

    using a single label in a point renderer, passing through the "data.text" value

  • get the setting of HTTP command in cfml

    How to get the setting for HTTP command in cfml?

    for example

    If the command HTTP

    GET /DATA/pg/index.cfm?lang=en HTTP/1.1

    Then, the parameter must be

    lang = en

    If the command HTTP

    GET /DATA/pg/index.cfm?lang=fr HTTP/1.1

    Then, the parameter must be

    lang = en

    Try to create a file named "cgitest.cfm" with the content:

    #cgi.query_string. #

    Go to http://localhost/cgitest.cfm?lang=en (or substitute the path on your server).

    The fact that HTTP_REFERER is filled makes me suspect that you have a redirect, such as CFLOCATION code, in your index.cfm file.

  • Under certain conditions see the popup on page (fragment) charge

    Hi Experts,

    We have an obligation to show a popup on the page load, if a certain condition is true.

    I have two fragments (home.jsff and profile.jsff). Initially when the user login, home.jsff is indicated and that there should be no popup.

    When the user goes to profile.jsff and save the changes, it must first redirect to home.jsff and show a popup with the confirmation message.

    I can't create a fragment separated for the popup where we need to redirect to profile.jsff and then redirect to home.jsff as said the requirement that the popup should display the content of home.jsff in the background.

    Also I can't use showPopup behavior during the loading of the page because it's a jsff.

    Please suggest how to implement this.

    Thanks in advance.

    Best regards

    Saurabh

    ... There's an even simpler option

    1. Add a hidden from the fragment output text element

    2 bind the output components text 'value' property to a bean property of manage (pair of getter/setter)

    3. when the getter of the value method is called, check the indicator that you defined for if you want to display the context menu or not

    4. If the indicator is such that the popup needs to be displayed, run the Java Popup

    4.a search the component RichPopup

    4.b set flags of the popup

    4.c unset flag to display the pop-up window (for the next time you need to put it)

    4.d see the popup

    Frank

  • imaqReadAVIFrame retrieves the empty image under certain conditions?

    Hello

    I'm having a problem where imaqReadAVIFrame (.) is the white recovery (all black images) under certain conditions.  The conditions seem to be when the height of the AVI file is equal to or greater than the width and the height is an odd number.  AVI files created by using the various AVI NI Vision (IMAQ 4.6.1, IMAQdx 4.6.1) functions in an application created in CVI 2012 on a computer running Windows 7 64 bit.  AVI files use MJPEG compressor, and they play back fine in an external program like VLC or Windows Media Player.  Any ideas on what this could be?  My solution for now is to not to allow the creation of AVI files where the height is odd and equal to or greater than the width that is not a boring restriction, but it seems like there's something weird happens with imaqReadAVIFrame().  I can provide some AVI files if necessary, but they are 16 + MB each.

    TStanley,

    I managed to reproduce what you see with your .avi files in a program I wrote.  I built a LabVIEW program that creates an AVI file which can be saved to memory and then uses code from the example finder to read who created the file.  I build the file to your specifications at the height is greater than the width, and the height being an odd number of pixels.  Something interesting about this, however, is that it seems to be a point where an odd height is acceptable.  Once you go below the height of 291 pixels, any odd height then works.  The files that I used are written as read in LabVIEW, but that the configuration should be irrelevant because we are seeing the same issue.  In addition, LabVIEW and LabWindows CVI calling the same dll to actually set up the code.

    In this, I think this question arises from the nature of the way you compress the. AVI file.  If you are interested to read a bit more about it, a useful link can be found here:

    http://www.manifest-tech.com/media_pc/avi_formats.htm

    However, what I think is happening, is it that MJPEG file compression format translates into creating files that cannot be read by our software unless the height in pixels is a multiple of 2 or the size of the file is below a certain limit.  To fix that, there is a simple solution. Compress the file with any of the other compression methods available (DV video, Cinepak Codec, codec Intel IYUV, Microsoft RLE, Microsoft Video) and you will be able to open the file without the black screen.  This worked for me and should solve all your problems.  I hope this gives you a bit of insight.

    Kind regards

    Keith M

    Technical sales engineer

  • Where is a good place to get the set of patches for old games

    Hello

    I've been looking for a good place to get the fixes for older games pc game.  I know that the best place is the site of publishers, but sometimes they stop making them available (e.g. FEAR).  I looked at a few well known places to get them, but they all require way too much personal information.  I don't feel comfortable giving my life away just to get a pc game patch.  It seems just a little scary to me for them to ask a lot of personal information.

    The games that I need patches for are Doom 3, Quake 4, AFRAID and prey.
    If you know of a good site, please report it.

    Wouldn't be nice if Microsoft made a website for it?  Then I could just connect you and get what I need lol.
    Thank you
    Jebidia

    Hello Jebidia,

    Thank you for using the Microsoft Windows Vista Forums.

    Yes, I understand your point of wanting to get your money to buy a game.  I recommend you always go to the site of the game manufactures video you must first update.  There are so many third party sites for patches, you want to be sure that it is a trustworthy site.  Please let me know if you have other questions/concerns.

    Of course, you can go to the link below for updates on games made by Microsoft/Windows:
    http://www.Microsoft.com/downloads/en/resultsForCategory.aspx?displaylang=en&CategoryID=1&sType=n_dc engineer in Support of James Microsoft answers visit our Microsoft answers feedback Forum and let us know what you think.

  • How to get the sql query result?

    Hello

    Currently I use LV2012 to connect to an Oracle database server. After the Oracle Express and Oracle ODBC driver facilities/settings made.

    I managed to use the SQL command to query the data through my command prompt window.

    Now the problem is, how to do the same task in Labview using database connectivity tools?

    I have build a VI to query as being attached, but I have no idea of what range to use to get the result of the query.

    Please help me ~ ~

    Here is a piece of code that I use to test the SQL commands, you can use the part that retrieves the results of sql.

    It is also possible to get the rear column headers, but it's for the next lesson!

    ;-)

  • How can I get the child to pass under the appropriate parent based on the name?

    I'm reading an .ini file and based on the name of the group, I want that child to go under this name. If I read in another file, and he wears the same group name, that I want the child to be able to go under this name. Right now I can't even the child to pass under a different group name when it is supposed to. He continues to go by the same name of Parent. Here is my code.

    parent of int = 0;

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Group', cbuf, BUFSIZE);

    InsertTreeItem (s_gMainWindow.managerTab, MANAGERTAB_TREE, VAL_SIBLING, 0,)
    VAL_NEXT, cbuf, NULL, 0, relative).

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Name', cbuf, BUFSIZE);
         
    InsertTreeItem (s_gMainWindow.managerTab, MANAGERTAB_TREE, VAL_CHILD, 0,)
    VAL_LAST, cbuf, NULL, 0, relative ++);

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Version', cbuf, BUFSIZE);
         
    SetTreeCellAttribute (s_gMainWindow.managerTab, MANAGERTAB_TREE, relate, 1, ATTR_LABEL_TEXT, cbuf); I can't do this correspond with the child column.

    Try this:

    parent of int = 0;

    int parent, index;

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Group', cbuf, BUFSIZE);

    parent = InsertTreeItem (s_gMainWindow.managerTab, MANAGERTAB_TREE, VAL_SIBLING, 0,)
    VAL_NEXT, cbuf, NULL, 0, relative).

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Name', cbuf, BUFSIZE);
    index = InsertTreeItem (s_gMainWindow.managerTab, MANAGERTAB_TREE, VAL_CHILD, parent,
    VAL_LAST, cbuf, NULL, 0, relative ++);

    Ini_GetStringIntoBuffer (iniText, 'Details', 'Version', cbuf, BUFSIZE);
    SetTreeCellAttribute (s_gMainWindow.managerTab, MANAGERTAB_TREE, index, 1, ATTR_LABEL_TEXT, cbuf);

    the idea is to keep the index of the item that you insert in order to reuse it when you want to edit the item.

  • Get-advancedsetting showing only a limited set of results

    Hi all

    I'm very new to using PowerCLI, so please be patient with me.

    I am trying to determine which of our virtual machines have the Advanced setting "device.hotplug" 'true '.

    I think I got the script to do so, the only question is, is not producing the expected results.

    When you run a command that does not filter results, it only returns results for 40 VM, when I expect to slightly more than 200.

    This is the command that I expect the return value for each virtual machine in a cluster:

    Get-Cluster-name of the "cluster" | Get - vm | Get-AdvancedSetting - name devices.hotplug | Format-Table-entity property, Name, Value - AutoSize

    I get a complete list of virtual machines, when I run:

    Get-Cluster-name of the "cluster" | Get - vm

    That should be all that you need to see my problem, however, for good measure and any comment, here is the little script I'm working on the only exit from the virtual computer with the "device-hotplug" setting enabled. Feedback or comments welcome.

    $hosts = get-cluster-name of the "cluster" | Get - vm |

    Where-Object {$_ .name-notlike 'exclude'}

    }

    $results = {foreach ($vihost in $hosts)

    Get-vm-name $vihost | Get-advancedsetting - name devices.hotplug |

    Where-Object {$_.} Value - notlike 'false'}

    }

    $results | format-table-entity property, Name, Value - AutoSize

    See you soon

    Lloyd

    Make sure that each VM has who progress together setting?

    Try like this, it should return all the virtual machines, also those who does not have the setting

    Get-Cluster-name "group" | Get - VM |

    Select Name,@{N='device.hotplug'; E={$_ | Get-AdvancedSetting - name devices.hotplug | Select value - ExpandProperty}}

  • Insert data into the same table based on certain conditions

    Hello. I'm new to this forum.
    I have to write a stored procedure to insert data in a table MYTABLE say, having a structure like:

    Col1 Col2 Col3... TotalInstallments CurrentInstallment PaidAmount MonthYear
    I have to insert all the data that it is in the same table (MYTABLE) except change some fields based on certain conditions:

    1. if PaidAmount > 0 & & CurrentInstallment < TotalInstallment then

    CurrentInstallment = CurrentInstallment + 1

    2. in the field MonthYear I have data ex. 01/2012, 11/2012 formate(month/year)...

    So, I have to insert data by incrementing the month and year. for example:

    If currentdata is 11/2012 next data will be 12/2012

    But following will be 01, 2013
    I have to select all records that belongs to the previous month (across the field MonthYear) and put the audit on each record selected and insert data and then turns them into table (MYTABLE) even.

    How to achieve that?

    Thank you.

    978184 wrote:
    Hello. I'm new to this forum.
    I have to write a stored procedure to insert data in a table MYTABLE say, having a structure like:

    Col1 Col2 Col3... TotalInstallments CurrentInstallment PaidAmount MonthYear
    I have to insert all the data that it is in the same table (MYTABLE) except change some fields based on certain conditions:

    1. if PaidAmount > 0 & CurrentInstallment

    CurrentInstallment = CurrentInstallment + 1

    2. in the field MonthYear I have data ex. 01/2012, 11/2012 formate(month/year)...

    So, I have to insert data by incrementing the month and year. for example:

    If currentdata is 11/2012 next data will be 12/2012

    But following will be 01, 2013
    I have to select all records that belongs to the previous month (across the field MonthYear) and put the audit & on each of the selected data record and insert then turns them into table (MYTABLE).

    You can do this way:

    This is not tested, but if you can provide the example of table structure and data (IN create table and insert scripts), it can be put to the test.

    insert into your_table
    (col1, col2, col3...current_installment, month_field)
    select col1, col2, col3..,
           current_installment +
           case when paidamount > 0 and current_installment < total_installment then
            row_number() over (
                                partition by column1, column2,.. columnn      -->You may choose partition if you want the
                                                                              --Increment of Current_installment to reset after particular combination ends
                                order by primary_key        -->Order the Increment, you may choose to add more columns to order by
                              )
          else
            0                                               --> if condition is not met, then Add 0
          end curr_installment,
          add_months(to_date(month_field, 'MM/YYYY'), 1) nxt_month
      from your_table;
    
  • Tecra S3 - how long the battery still works under normal conditions of use?

    I have Tecra S3, I know the duration of battery power under normal conditions of use. It does not work for more than 80 80. It is still new to laptop.

    Hello

    AFAIK the Tecra S3 has been delivered with the battery 4700mAh standard.
    The Tecra S3 also supports other high capacity batteries. For example:

    PA3509U-1BRM 9-cell Li-ion 7050mAh
    PA3357U-3BRL 12Cell Li - ion 8800mAh

    These batteries are much stronger than the standard battery and should works more than 80 min.
    Additional if you think that there is something wrong with your battery life then I would recommend contacting the Toshiba service partner for the control of that party. But like I said above; These large capacity batteries are working longer than the standard battery.

  • set of results based on condition

    Hi all

    I have a requirement that contains three conditions which means my final result set is derived
    3 different conditions.
    I have three tables and I Union to get the result set.
    ex:
     Select cust_id, cust_name , cust_add, 'A' condition  
                From  Table1 {CODE}
             union
                Select cust_id, cust_name , cust_add, 'B' condition
                  From  Table2
             union
                Select cust_id, cust_name , cust_add, 'C' condition
                  From  Table3                                                         
       Values are:
                   cust_id           cust_name                cust_add           condition
                     100               roy                       ABC                   A
                     100               roy                       ABC                   B
                     101               eddy                                            C
                     102               pat                                             B
                     102               pat                                             C
    Instead of having the same information on two different lines, I want to have the same line with 2 another column showing what conditions he met.
       i require values like this:
                    cust_id           cust_name               cust_add           condition1          condition2        condition3
                     100               roy                       ABC                   A                   B
                     101               eddy                                            C
                     102               pat                                             B                   C
    Can someone help me to achieve this type of result set.
    Thank you!

    Hello

    This is called a pivot

    WITH     union_query     AS
    (
         Select cust_id, cust_name , cust_add, 'A' condition
                From  Table1 {CODE}
             union
                Select cust_id, cust_name , cust_add, 'B' condition
                  From  Table2
             union
                Select cust_id, cust_name , cust_add, 'C' condition
                  From  Table3
    )
    ,     got_rnum     AS
    (
         SELECT     union_query.*
         ,     ROW_NUMBER () OVER (PARTITION BY cust_id)     AS rnum
         FROM     union_data
    )
    SELECT       cust_id,      cust_name,     cust_add
    ,       MAX (CASE WHEN r_num = 1 THEN condition END)     AS condition1
    ,       MAX (CASE WHEN r_num = 2 THEN condition END)     AS condition2
    ,       MAX (CASE WHEN r_num = 3 THEN condition END)     AS condition3
    FROM       got_rnum
    GROUP BY  cust_id,      cust_name,     cust_add
    ORDER BY  cust_id,      cust_name,     cust_add;
    

    It's a bit more complicated than some points of articulation, because there is nothing in your raw data that tells you which column of output directly each condition belongs in. (in other words, for the results you requested, a 'C' could go to condition1 or condition2 and condition3: just by looking at the line with the 'C' we cannot tell who.) We do this by using the function ROW_NUMBER analytic, and, like a lot of things involving analytic functions, which requires a separate subquery.

  • How do you get the set of an old iPhone?

    I inherited an old iPhone and I'm trying to set it up as an iPod as a device for my grandchildren. How can I determine the series of the iPhone and can I download iOS 7.0 or such so that the applications can be downloaded?

    First, you will need a SIM in there to activate it with Apple (you can out it then - just to be there to complete the stages of activation).

    If you plug into iTunes, try to update to iOS, system update Apple will offer only the last version compatible with the material.  If iTunes says no update is available, then you are running the latest available for that material.  If there is a newer version available iTunes will determine the latest version for that material and provide only that the update version.

Maybe you are looking for