Re: Calculating product from rows - (aggregate product )

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: Calculating product from rows - (aggregate product )
Дата
Msg-id gtmhfi$u26$2@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на Calculating product from rows - (aggregate product )  (Allan Kamau <allank@sanbi.ac.za>)
Ответы Re: Calculating product from rows - (aggregate product )  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Re: Calculating product from rows - (aggregate product )  (Dennis Brakhane <brakhane@googlemail.com>)
Список pgsql-general
On 2009-05-04, Allan Kamau <allank@sanbi.ac.za> wrote:
> Hi
>
> I would like to calculate a product of a field's values of a relation,
> this function may multiply each value and give the result as a single
> float number.
>
> For example:
>
>
> CREATE table imaginary(id INTEGER NOT NULL, some_field FLOAT
> NULL,primary key(id));
>
> INSERT INTO imarginary(1,0.333);INSERT INTO imarginary(2,0.667);INSERT
> INTO imarginary(3,0.4);
>
>
> SELECT prod(some_field) FROM imarginary;
>
>
> would give 0.0888444 (which is 0.333*0.667*0.4)
>
>
> Is there an already existing function that does this.

here's one way to cheat: logarythms.

select exp(sum(ln( thiscolumn ))) from foo;

 :^)


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

Предыдущее
От: "Markus Wollny"
Дата:
Сообщение: diff-/patch-functionality for text-type data inside PostgreSQL
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: keeping track of function execution