How to compare a value with two record of Oracle in the same time?

I have a table like below:

enter image description here

The record of id = 1, means that value >0 and value <=200.

The record of id = 2, means that value >200 and value <=1500.

The values are ordered by such analogy.

Now I have a value of 4000, I want to get the corresponding id value(should be 3).

Are there better way to write SQL compare with?

select * from table_name where value >=4000 and rownum = 1;


Source: oracle

Leave a Reply