Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: getting the nearest number from a column
On Mon, 09 Apr 2007 00:50:10 -0700, matt 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
1 with close as (select ename,empno,deptno,sal,
2 min(sal) over (order by abs(sal-100)) as cls 3 from emp)
-- http://www.mladen-gogala.comReceived on Mon Apr 09 2007 - 07:49:42 CDT