[10g] way to find the least value greater than a value?

I have a simple (I think) question...

Part 1:
Is there a way to determine the least value among a set of values, which is greater than 0?

A few examples:
Set of values:
{0,1,2,3}
Return value:
1

Set of values:
{0,5,10,20,100}
Return value:
5

Set of values:
{1,4,9,11}
Return value:
1
Part 2:
Same thing, but greater than some given value, 0 is not necessary.
Set of values:
{0,1,2,3}
Parameter value: 
2
Return value:
3

Set of values:
{0,5,10,20,100}
Parameter value: 
2
Return value:
5

Set of values:
{1,4,9,11}
Parameter value: 
2
Return value:
4
In particular, I'm looking for an effective way to achieve this. I think I can do it with a set of CASE statements, but it becomes really complex values compare more than you.

My first thought was to use the function LESS, but which does not allow me a way to use a parameter.

Any suggestions?

Hello

Thanks for posting the sample data.
I know that it takes hard work to do, but it's really help people who want to help you. Sometimes, it can help you, too, giving you new perspectives on what the problem really is. As often do not, when I am confused by something and need help, I discovered an answer while assembling a test script and write a description of the problem.

You can use the function LESS, with CASE expressions as arguments, to do what you want:

SELECT     ord_nbr
,     seq_nbr
,     time_spent /
     CASE
          WHEN     comp_qty > plan_qty
          THEN     LEAST ( CASE  WHEN ord_qty - scrap_qty > 0 THEN ord_qty - scrap_qty ELSE 1E99 END
                     , CASE  WHEN plan_qty              > 0 THEN plan_qty           ELSE 1E99 END
                     , CASE  WHEN comp_qty            > 0 THEN comp_qty         ELSE 1E99 END
                     )
     END     AS unit_time
FROM     ord_detail
;

This means that your actual data are never as large as 1E99, and at least one of the three expressions will be greater than 0.
If or any of these assumptions are false, I'm sure we can find a solution, but it will probably be even messier.

It should work in Oracle 8.1.

Tags: Database

Similar Questions

  • best way to find the maximum value that is less than a specific value?

    Hello guys,.

    What is the fastest way to find a record that has value max of a field and there is a limitation to a specific value for ex:

    example 1:
    create table dummy(master_id number, detail_id number, some_value varchar2(80));
     
    insert into dummy values (1,1,'bla bla1');
    insert into dummy values (1,2,'bla bla2');
    insert into dummy values (1,3,'bla bla3');
    insert into dummy values (2,1,'bla bla4');
    insert into dummy values (2,2,'bla bla5');
    insert into dummy values (2,3,'bla bla6');
    insert into dummy values (2,4,'bla bla7');
    commit;
    I want to get:
    1 3 bla bla3
    2 4 bla bla7
    And these applications give a correct result:
    Select * 
    from   dummy d1
    where  detail_id = (select max(detail_id) from dummy d2 where d2.master_id = d1.master_id);
     
    OR next one which i prefered.
     
    Select *
    From   (Select d1.* , row_number() over(partition by master_id order by detail_id desc) r
            from   dummy d1)
    Where  r = 1;
    If these solutions are enough or is there a better way?

    Edited by: elcaro on 13.Ara.2011 04:02

    Edited by: elcaro on 14.Ara.2011 04:31

    Please try this with your new test tables:

    select m.master_id,
           m.master_data,
           max(d.id) keep (dense_rank last order by data_value, d.id) d_id,
           max(d.master_id)  keep (dense_rank last order by data_value, d.id) d_master_id,
           max(data_value) keep (dense_rank last order by data_value, d.id) d_data_value,
           max(date_data)  keep (dense_rank last order by data_value, d.id) d_date_data
    from master_dummy m, detail_dummy d
    where m.master_id=d.master_id
    and d.date_data <= to_timestamp('04012010','ddmmyyyy')
    group by m.master_id, m.master_data
    

    Published by: hm on 14.12.2011 05:18

    (I added d.id column in the order by the dense_rank. clause that could make a difference when there is more than one line with the same data_value).

  • Is it possible to connect a simple 1 d array to a digital indicator or what would be the best way to display the numeric values of the array on the front panel?

    Is it possible to connect a simple 1 d array to a digital indicator or what would be the best way to display the numeric values of the array on the front panel? Examples or suggestions would be greatly appreciated.

    Thank you

    Tunis

    Thank you Adam, it's originally in a while loop, I placed it in a loop for example, wired County in the for loop and presto, this son of a digital indicator. It works very well. Thanks for the help folks.

  • Find the max value

    Hi team,

    I have the following query where I need to find the max value

    [code]

    with t as)

    Select 'L1' R_nm, R_Data 'Data', 'Obj' R_Obj, r_prec 'Wd', '2' double val

    Union of all the

    Select 'L1', 'Data', 'Obj', 'No', '4' double

    Union of all the

    Select 'L2', 'Data', 'Obj', 'No', '4' double)

    Select t.*, max (val) on rk (partition r_nm, r_data, r_obj) of t

    [/ code]

    My results should be

    [code]

    r_nm r_data r_obj r_prec rk val

    L1 Data Obj 1 2 Wd

    L1 data Obj 4 No.2

    L2 Data Yes 1 1 Obj

    [/ code]

    Thank you


    Hello

    It seems that you are not interested in the MAX at all.  Looks like you want to classify the lines, such as one that has the lowest value is assigned the number 1, the 2nd line with the lowest values gets 2,... and line with him gets N-th lowest value N.  If is not serious if the MAX is 4, 2 or 420.

    Here's a way to do it:

    SELECT T.*

    , RANK () OVER (PARTITION BY r_nm, r_obj)

    ORDER BY val

    ) AS rk

    T

    ORDER BY r_nm, r_obj

    val

    ;

    Depending on how you want to deal with links, you can use ROW_NUMBER or DENSE_RANK instead of RANK.

  • Find the average value of a buffer

    Hello

    In my VI Panel, I have a digital control, a button and a digital display.

    When the user, enter a number in numerical order and press the button, the digital display should show the average value of all the past 5 values entered in the digital control, for example:

    1st entry: 10-online average = 10 (as sum = 10)

    2nd type: 0-online average = 5 (as sum = 10 + 0 = 10)

    3rd enter: 5-online average = 5 (you get the idea...)

    4 enter: 1-average online = 4

    5 enter: 14-online medium = 6

    6 enter: 2-online average = 4.4 (sum = 0 + 5 + 1 + 14 + 2 = 22, because the 1st value is thrown)

    How to write this VI?

    Thank you!!

    You can also use arrays to hold the data in a registry change and find the average value of the last five items.

    Good luck

  • Find the minimum value of the table in time...

    Firstly that it is not "find the min value in the table.

    It is:

    I have a table that changes its values at each iteration, and I want to compare the new values with previous values and make a new array with the minimum values...

    In C++, it would be like this:

    int main() {}

    int array [8];

    int min [8];

    int i;

    for (i = 0; i<>

    min [i] = 1000000; Initialize minimum table with a high value

    }

    {while (1)}

    Array = update_array ();

    for (i = 0; i<>

    If (array [i]<>

    min [i] = array [i];

    }

    }

    do things...

    }

    return 0;

    }

    IM new to labview and it always confuses me a lot...

    Thanks in advance.

    Using the function Max & Min regular (not table Max & min as you know) with tables and a good will of employment registry change.  Max Min &, as most of the digital functions, is polymorphic and works witt tables as well as scalars.

    Lynn

  • I'm moving from Vista to Windows 7. I get a question that tells me that I need a BIOS upgrade. I have an Inspiron 1720 laptop model. Is there a way to find the update is necessary?

    I'm moving from Vista to Windows 7. I get a question that tells me that I need a BIOS upgrade. I have an Inspiron 1720 laptop model. Is there a way to find the update is necessary?

    original title: bios update

    Hello

    you have a problem here as Dell does not have Windows 7 drivers available for your model of laptop etc, etc.

    Unfortunately, you need these Windows 7 drivers, etc. to upgrade to Windows 7

    read the information on your laptop on the link below

    http://support.Dell.com/support/downloads/DriversList.aspx?c=us&l=en&s=Gen&OS=WLH&OSL=en&SystemID=INS_PNT_PM_1720&CATID=-1&impid=-1

    For more information contact Dell about this

    Dell support:

    http://support.Dell.com/

    Dell support at the link above.

    http://en.community.Dell.com/support-forums/default.aspx

    Dell's Support Forums at the link above.

  • is there a way to find the user (lanid) based on the name of the computer.

    is there a way to find the user (lanid) based on the name of the computer. I try nbtstat - has, but it don't did me not what I needed.

    is there a way to find the user (lanid) based on the name of the computer. I try nbtstat - has, but it don't did me not what I needed.

    Do you mean the name of a Windows of a remote computer logon account? There is more than one because Windows 7 allows multiple concurrent interactive sessions. In any case, this could point you in the right direction:

    PsExec \\NameOfPC cmd.exe / user: YourUserName
    PsLoggedOn
    The first command will not work unless you have an account admin on the remote machine.
    You can download the PS tools from here.
  • Display a value in the column only if the number is greater than 1

    I need to return a value in the only if column the the count is greater than 1 for the same column.

    Example table:

    FOOD_TYPE Agenda COST_TO_BUY SELL_PRICE
    Ice creamChocolate0.502.00
    Ice creamVanilla0.502.00
    Ice creamStrawberry0.502.00
    ChickenWings2.005.00
    Bovine meatSteaks8.0015 h 00
    Bovine meatRoast10 h 006:00 pm

    In this example, I want to choose the POINT of FOOD_TYPE, SUM (COST_TO_BUY) AND SUM (SELL_PRICE), but I want only to select the ITEM if there is more than 1 points in the FOOD_TYPE.

    I tried all kinds of grouping and even including a case statement in select it as follows:

    CASE

    WHEN (COUNT (DISTINCT POINT) > 1)

    THEN THE POINT

    ELSE "

    END

    However, this is denied when I group because it forces me to use the POINT as a group and I can't use the set statement in the GROUP BY because it has an aggregate function.

    Help, please!

    with

    power as

    (select food_type 'Beef', 'Steaks' article, cost_to_buy 8.00 15.00 sell_price of all the double union)

    Select 'Beef', 'Roast', 10.00, 18.00 double Union all

    Select 'Chicken', 'Wings', 2.00, 5.00 double Union all

    Select 'Ice Cream', 'Chocolate', 0.50, 2.00 double Union all

    Select "Ice Cream", "Vanilla", 0.50, 2.00 double Union all

    Select "Ice Cream", "Strawberry", 0.50, 2.00 double

    )

    Select food_type 'Type of food. "

    cases where the head (separate) over (partition food_type) > 1 then end point "Item,"

    TO_CHAR (cost_to_buy, 'fm990.00') "Purchase cost"

    TO_CHAR (sell_price, 'fm990.00') 'selling price '.

    food

    food_type desc order

    Food Type Item Purchase cost Sell Price
    Ice cream Chocolate 0.50 2.00
    Ice cream Strawberry 0.50 2.00
    Ice cream Vanilla 0.50 2.00
    Chicken - 2.00 5.00
    Bovine meat Roast 10 h 00 6:00 pm
    Bovine meat Steaks 8.00 15 h 00

    Concerning

    Etbin

  • PL/SQL loop to find the minimum value

    I want to find the minimum value from a table using the pl/sql loop

    I have data format below.

    1 ABC 2

    1 ABC 20

    1 ABC 500

    1 ABC 2000

    XYZ 2 250

    JKL 3 300

    MNP 3 350

    3 KLM 400

    I wrote the code below. His does not work. Please suggest.

    Set serveroutput on
    declare
    x number: = 3;
    y VARCHAR2 (3): = 'ABC ';
    fmin number: = 0;
    number of Fmax: = 0;
    Start
    for rec in (select sal from test
    where id = name and x = y) loop


    If rec.sal > fmin then
    fmin: = rec.sal;
    on the other
    FMAX: = rec.sal;
    fmin: = fmax.
    end if;
    end loop;
    dbms_output.put_line (Fmax);
    end;
    /

    I want to output 2 on top of code.

    Thanks in advance

    Why PL/SQL? SELECT MIN (SAL) OF TEST will be more rapid and much less coding. In any case:

    declare

    number of v_min_sal;

    Start

    for v_rec in a loop (select sal from emp)

    If nvl (v_min_sal, v_rec.sal + 1) > v_rec.sal

    then

    v_min_sal: = v_rec.sal;

    end if;

    end loop;

    dbms_output.put_line (' lowest salaray is "' |") v_min_sal | '"');

    end;

    /

    The lowest Salaray is "800".

    PL/SQL procedure successfully completed.

    SQL >

    SY.

  • I already pay for my creative cloud through license and there is no way to find the serial number

    I already pay for my creative cloud through license and there is no way to find the serial number. I have in my account adobe my order number and everything. When I open creative cloud and install the 2 app photo and the Lr, ask me to pay again.

    Who knows something?

    Cloud programs are not serial numbers

    Your subscription to cloud shows correctly on your account page?

    If you have more than one email, you will be sure that you use the right Adobe ID?

    https://www.adobe.com/account.html for subscriptions on your page from Adobe

    .

    If Yes

    Some general information for a subscription of cloud

    Cloud programs don't use serial... numbers you, connect you to your cloud account paying to download & install & activate... you may need to sign out of the cloud and restart your computer and log into the cloud for things to work

    Sign out of your account of cloud... Restart your computer... Connect to your paid account of cloud

    -Connect using http://helpx.adobe.com/x-productkb/policy-pricing/account-password-sign-faq.html

    -http://helpx.adobe.com/creative-cloud/kb/sign-in-out-creative-cloud-desktop-app.html

    -http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html

    -http://helpx.adobe.com/creative-suite/kb/trial--1-launch.html

    -ID help https://helpx.adobe.com/contact.html?step=ZNA_id-signing_stillNeedHelp

    -http://helpx.adobe.com/creative-cloud/kb/license-this-software.html

    .

    If no

    This is an open forum, Adobe support... you need Adobe personnel to help

    Adobe contact information - http://helpx.adobe.com/contact.html

    Chat/phone: Mon - Fri 05:00-19:00 (US Pacific Time)<=== note="" days="" and="">

    -Select your product and what you need help with

    -Click on the blue box "still need help? Contact us. "

  • I have photoshop elements for Christmas 14.  When I go to install it, he invited me for a serial number which I can't find anywhere on the disc, disc sleeve or box product.  Y at - it another way to find the serial number for this product, so I can't cont

    I have Photoshop elements for Christmas 14.  When I go to install it, he invited me for a serial number which I can't find anywhere on the disc, disc sleeve or box product.  Is there another way to find the serial number for this product, so I can continue the installation?  And no, I have not installed or registered this product before.

    Redemption Code http://helpx.adobe.com/x-productkb/global/redemption-code-help.html

    - and https://forums.adobe.com/thread/1572504

    Find your http://helpx.adobe.com/x-productkb/global/find-serial-number.html serial No.

  • When you create a PDF from a scanner, is there a way to set the default value for the size of 8.5 x 11 letter custom every time I make a PDF from a scanner?

    When you create a PDF from a scanner, is there a way to set the default value for the size of 8.5 x 11 letter custom every time I make a PDF from a scanner?

    Hi kevin7frg,

    You can go to "file > create > scanner > configure presets PDF»

    The dialog box that appears, you can choose 8.5 X 11 as the default width and height of PDF pages to scan.

    Hope that helps.

    Kind regards

    Ana Maria

  • Is there a way to find the actual size of the patterns as if all the HWM meter resetting tables?

    RDBMS Version: 11.2.0.3

    Platform: Oracle Linux 6.2

    The following query gives the size of patterns. But if there is no large table in these schemas that can be narrowed (IE. High tide being reset) then the actual size of these schemas will be less indicated below.

    Is there a way to find the size of a schema, as if the reset of the HWM in all tables in it?

    SQL > select master, sum (bytes/power (1024,3)) GB of dba_segments group by owner by Go order desc;

    OWNER                                  GB

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

    SBTOEL 1798.49951

    MIGPHS 228.772522

    SYS 22.4576416

    MIGSTATIC 4.79718018

    MIGRFS 2.39648438

    SYSTEME.523681641

    SYSMAN.277893066

    .

    .

    .


    Tom wrote:

    RDBMS Version: 11.2.0.3

    Platform: Oracle Linux 6.2

    The following query gives the size of patterns. But if there is no large table in these schemas that can be narrowed (IE. High tide being reset) then the actual size of these schemas will be less indicated below.

    Is there a way to find the size of a schema, as if the reset of the HWM in all tables in it?

    SQL > select master, sum (bytes/power (1024,3)) GB of dba_segments group by owner by Go order desc;

    OWNER                                  GB

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

    SBTOEL 1798.49951

    MIGPHS 228.772522

    SYS 22.4576416

    MIGSTATIC 4.79718018

    MIGRFS 2.39648438

    SYSTEME.523681641

    SYSMAN.277893066

    .

    .

    .

    given zero HWM does NOT change the amount of consumed disk space.

  • Is there a way to get the new value assigned to a column of series (DG4IFMX)

    Hi people,

    I need to insert records into a table whose primary key is a column of series (even as a trigger on a primary key in Oracle). I have been informed that the way to trigger the next value is to insert a zero in the column, which is fine. The problem is, that I need to know what the next value that has been assigned, and there is not enough time between the transaction to do a 'select max (column_name)', for example. Is there something (maybe a function) that responds to this need, and I don't know about it?

    Thanks, any idea would be appreciated.

    -Adam vonNieda

    The gateway offers the PASSTHROUGH - described in more detailed manual - package which allows you to send anything to the foreign database without being touched by Oracle.
    Depending on your function, you can use the DBMS_HS_PASSTHROUGH. The EXECUTE_IMMEDIATE package and if you need to retrieve something that you could use:
    dbms_hs_passthrough. Parse
    DBMS_Hs_Passthrough.fetch_row
    dbms_hs_passthrough.get_Value

Maybe you are looking for

  • Qosmio X 500-110 - Webcam pending issue

    Any idea how to solve the "question webcam not initiallized? This machine seems the camera and prints print sensor disconnect automatically and then youneed to restart the system. Its really irritating.also after you have installed the new 1.4 BIOS t

  • Vista product key error CODE 0xC004f050

    WHEN I RECOVER THE SYSTEM TO SYSTEM TOOLS AND FINALLY HE ASKED ME THE PRODUCT KEY FOR WINDOWS... I WRITE THE PRODUCT KEY THAT IS LOCATED BEHIND THE LAPTOP AND I GOT THIS ERROR CODE... A WRITTEN WILL ALSO GET A NEW PRODUCT KEY WHAT IS PLANNED?

  • Creating groups of objects on the ASA/FWSM

    It doesn't seem possible, but I would like to check if this is possible. I want to create a group for example NMS and have this group associated with 5 different NMS on my network IP addresses. So I want to configure ASA to simply allow any intellect

  • Smartphones Strange blackBerry Tour icon

    Hi, this is my first BB it s a 8520 and today I received a new icon that I have no idea what it is, it is a yellow circle with a grid inside and has a number 2 next door like the one you get when you will receive 2 emails. I already have it restarted

  • ORA-01427: einreihig subquery returns multiple rows

    I've been off queries running for awhile, and this error is making me take what I left little hair.   I searched and found a lot of topics about this, but it does not appear to meet this request.  Rather than continue blabbering...SELECT THE DME. ITE