Re: Please help with SQL
Posted in 1996
Douglas Wilson — — source: Informix-list mailing list archive (1991-1998)
Vitaly E. Kursitis wrote:
>
> 1. There is a table "tab1" that has astrucure like this:
>
> ! koef ! value1 ! value2 !
> ! float ! float ! float !
>
> Using ESQL/c I calculated koef and I need to find the nearest
> koef in this table in order to get the corresponding value1 and
> value2 from there. How can I do it using SQL?
select * from tab1
where koef in
(select max(koef) from tab1
where koef<=?)
union
select * from tab1
where koef in
(select min(koef) from tab1
where koef>=?)
Of course this will more than likely return more than one row,
but its easy to pick
the appropriate one with the closest koef.
Hope you have an index on koef.
*** Disclaimer: These are the opinions of the poster not Amgen Inc.***