Re: select records by nearest value

Поиск
Список
Период
Сортировка
От Frank Bax
Тема Re: select records by nearest value
Дата
Msg-id 4DCE7535.9060908@sympatico.ca
обсуждение исходный текст
Ответ на select records by nearest value  (e-letter <inpost@gmail.com>)
Список pgsql-novice
On 05/14/11 06:49, e-letter wrote:
> Readers,
>
> A database is structured as follows:
>
> 1 text1
> 1000 text2
> 500 text3
>
> where column 1 consists of integers. Is it possible to create query
> that will select the most appropriate records for a sum of integers.
> For example, if the target sum of integers is 50, is it possible to
> select a set of records that will be closest to this value?



I think your question is a variation of the "nearest neighbour" problem.

I found this page useful, even though I do not use PostGIS.

http://www.bostongis.com/PrinterFriendly.aspx?content_name=postgis_nearest_neighbor

In your case the "distance" function might be as simple as
    "ABS(id - 50)"
where "id" is the first column in your sample table above.

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

Предыдущее
От: e-letter
Дата:
Сообщение: select records by nearest value
Следующее
От: Joshua Tolley
Дата:
Сообщение: Re: More WAL archiving/backup questions