Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Greatest value less than

Greatest value less than

From: <jkdufair_at_my-deja.com>
Date: Fri, 06 Aug 1999 02:36:55 GMT
Message-ID: <7odho6$bjs$1@nnrp1.deja.com>


I have a table which is essentially:

key     level   property
---     -----   --------
a       100     foo
b       250     foo
c       500     foo
d       100     bar
e       250     bar
f       500     bar

and, at runtime, I'll get a value, x, and a property, p. I need to find the key that corresponds to the largest value less than or equal to x and also to property p. I came up with the following query:

select key
from table
where level = (select max(level)

               from table
               where level <= x and
                     property = p) and
      property = p;

This seems awkward to me. Is there a more elegant solution? TIA.

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't. Received on Thu Aug 05 1999 - 21:36:55 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US