Re: [SQL] calculating percentages

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Good <tomg(at)nrnet(dot)org>
Cc: "PostgreSQL::SQL List" <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: [SQL] calculating percentages
Date: 1999-07-12 16:57:19
Message-ID: 20534.931798639@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thomas Good <tomg(at)nrnet(dot)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

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Good 1999-07-12 16:57:45 Re: [SQL] calculating percentages
Previous Message Tom Lane 1999-07-12 15:06:56 Re: [SQL] calculating percentages