Re: apply limit to sum function

Поиск
Список
Период
Сортировка
От e-letter
Тема Re: apply limit to sum function
Дата
Msg-id CAET1fe6XJR0fqnqDdG8AMrmVXeX7VZ0siKjd3w5i0zQM6RUkpA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: apply limit to sum function  (Michael Wood <esiotrot@gmail.com>)
Список pgsql-novice
On 29/04/2012, Michael Wood <esiotrot@gmail.com> wrote:
>
> e.g. do you want to generate all possible permutations of your values
> and then find the sums that are less than your target?  If so, how do
> you decide which subset of rows to return?
>

Ideally, yes but that would make solution only via the "knapsack"
combination algorithm type of method?

> i.e.:
>
> 1: (text1, 10) => 10
>
> 2: (text2, 12) => 12
>
> 3: (text3, 23) => 23
>
> 4: (text1, 10), (text2, 12) => 22
>
> 5: (text1, 10), (text3, 23) => 33
>
> 6: (text1, 10), (text2, 12), (text3, 23) => 45
>
> Only options 1 and 2 are < 22, so I assume you're looking for either
> (text1, 10) or (text2, 12) as an answer given this example data?  How
> do you choose which one?
>

Would like to be able to choose 'text1' and 'text2' on the basis of
the sum of the values for the tuples being to the target value.

> Or do you just want to take the data in the order given and add the
> values until the total goes above 22 and then return the rows you had
> just before going over the target value?
>

Yes, that would be acceptable: read values in order in the table until
the sum reaches a target value, then return these rows.

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

Предыдущее
От: Michael Wood
Дата:
Сообщение: Re: apply limit to sum function
Следующее
От: "Paul ."
Дата:
Сообщение: PostgresSQL 8.4 - Data output - Newline