Re: Finding nearest numeric value

Поиск
Список
Период
Сортировка
От Peter Fein
Тема Re: Finding nearest numeric value
Дата
Msg-id 43034CD5.5090901@pobox.com
обсуждение исходный текст
Ответ на Re: Finding nearest numeric value  (Sean Davis <sdavis2@mail.nih.gov>)
Список pgsql-general
Sean Davis wrote:
> On 8/17/05 8:50 AM, "Poul Møller Hansen" <freebsd@pbnet.dk> wrote:
>
>
>>Does anyone know how to find the row with the nearest numeric value, not
>>necessarily an exact match ?
>
>
> To find the nearest value in number_column to some CONSTANT (where you
> replace constant with a number), try:
>
> select *,(number_column - CONSTANT)^2 as d from tablename order by d limit
> 1;
>

Save yourself some cycles - use abs() instead of exponentiation.


--
Peter Fein                 pfein@pobox.com                 773-575-0694

Basically, if you're not a utopianist, you're a schmuck. -J. Feldman

В списке pgsql-general по дате отправления:

Предыдущее
От: Csaba Nagy
Дата:
Сообщение: Re: Finding nearest numeric value
Следующее
От: "Jim C. Nasby"
Дата:
Сообщение: Re: How to implement table caching