Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: getting the nearest number from a column
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