Re: [SQL] calculating percentages

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] calculating percentages
Дата
Msg-id 20534.931798639@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [SQL] calculating percentages  (Thomas Good <tomg@nrnet.org>)
Список pgsql-sql
Thomas Good <tomg@nrnet.org> writes:
> On Mon, 12 Jul 1999, Tom Lane wrote:
>> Pretty much just like that.  What problem are you having?

> The divison rtns 0, which multiplied by 100, rtns 0.

If your data is stored as int fields, then you'd get integer division,
which sounds like what you're getting.  You want a floating-point
division, which you'd get by promoting to float:
SELECT (current_value::float8/target::float8) * 100;
        regards, tom lane


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

Предыдущее
От: Thomas Good
Дата:
Сообщение: Re: [SQL] calculating percentages
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Left joins