sql - How can I find a particular row from a particular table? -


i want find specific field of specific column particular table based on user provided value. unknown value contain specific column field. clear:

    table1    --------------    | range|value|    --------------    | 100  |0    |       | 200  |2    |      | 300  |9    |     | 400  |15   |    | 500  |20   |    -------------- 

from table1
if user provided value between 0 100 result 0,
if user provided value between 101 200 result 2,
if user provided value between 201 300 result 9
, on. example if user provided value 50 result 0, if user provided values 499 result 20.

if range column value fixed can find result using between function or <= , >= operator. here range column value unknown. how can solve problem?

you can use combination of order by , rownum pseudo column select best row:

select value (   select *      table1    range >= :p_range   order range ) rownum < 2 

alternatively, can compute explicit ordering using row_number() analytic function , use filter results:

select value (   select t.*, row_number() on (partition 1 order range) rn      table1 t    range >= :p_range   order range ) rn = 1 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -