best way to select from a range of values?

From: <mh_at_pixar.com>
Date: Mon, 06 Jul 2009 01:42:02 GMT
Message-ID: <KDc4m.10424$Dx2.545_at_flpi146.ffdc.sbc.com>



given this table:

x y
-- -

10 a
20 b
30 c

I want the best way to to map values [10,20) -> a
                                     [20,30)] -> b
                                     [30,inf) -> c

Right now I'm using a query like:

    select y from foo

     where x=(select max(x) from foo
               where x<=21);

Is there a better way to do this? Is there an analytic function that might help?

Many TIA!
Mark

create table foo as
select 10 as x ,'a' as y from dual union select 20,'b' from dual union
select 30,'c' from dual;

  • returns: a,b,b: select y from foo where x=(select max(x) from foo where x<=19); select y from foo where x=(select max(x) from foo where x<=20); select y from foo where x=(select max(x) from foo where x<=21);

--

Mark Harrison
Pixar Animation Studios Received on Sun Jul 05 2009 - 20:42:02 CDT

Original text of this message