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 -> Re: getting the nearest number from a column

Re: getting the nearest number from a column

From: <jarl_at_mimer.com>
Date: 11 Apr 2007 00:41:18 -0700
Message-ID: <1176277278.800613.138930@l77g2000hsb.googlegroups.com>


Something like this may work:

SELECT sal FROM saltable
GROUP BY sal
HAVING ABS(1450 - sal) =
  (SELECT MIN(ABS(1450 - sal)) FROM saltable);

/Jarl

On Apr 9, 9:50 am, "matt" <reflectio..._at_gmail.com> wrote:
> I have a table with a column called salary. There are other columns
> as well but for the most part irrelevant to my problem. I want to be
> able to retrieve the closest salary value based on what a user
> inputs.
>
> SAL
> ===
> 4000
> 3200
> 2900
> 2000
> 800
>
> user input: 1450
>
> I would like to get back "2000" as the closest value. I don't
> seem to see a useful operator such as "TOP" in mssql.
>
> Any help would be appreciated.
> Thanks
Received on Wed Apr 11 2007 - 02:41:18 CDT

Original text of this message

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