Say I have the following data
Name Value
Imagine that they are volumes of boxes. I have some items that I want to put in boxes, and I want the smallest box. I need a SQL query that will:
- Return a row with the smallest row larger than my query parameter
- If there is no such line, return the largest line.
It is easy to split this into two queries (i.e., query point 1 first, and if no rows are returned, select the largest number from the table). However, I like to do something in one request, if possible, to eliminate overhead (both code switching and context switching), and it looks like it should be possible. This is probably very obvious, but the sun shines on me all day, and I canβt think!
So, for example, I want the query to return 10 if you use parameter 5, 100, if you use parameter 15 and 1000, if you use something greater than 100 (including numbers greater than 1000).
I am on Oracle 11g, so any special Oracle friendliness is fine.
source share