Re: [SQL] calculating percentages - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] calculating percentages
Date
Msg-id 20534.931798639@sss.pgh.pa.us
Whole thread Raw
In response to Re: [SQL] calculating percentages  (Thomas Good <tomg@nrnet.org>)
List 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 by date:

Previous
From: Thomas Good
Date:
Subject: Re: [SQL] calculating percentages
Next
From: Peter Eisentraut
Date:
Subject: Left joins