pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Good <tomg@nrnet.org>
Cc: PostgreSQL::SQL List <pgsql-sql@postgreSQL.org>
Subject: Re: [SQL] calculating percentages
Date: Mon, 12 Jul 1999 12:57:19 -0400
Message-ID: <20534.931798639@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.3.96.990712104853.16755A-100000@mailhost.nrnet.org>

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



view thread (13+ messages)  latest in thread

Message-ID: <20534.931798639@sss.pgh.pa.us>
Permalink:  ../20534.931798639@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20534.931798639@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, tomg@nrnet.org
  Subject: Re: [SQL] calculating percentages
  In-Reply-To: <20534.931798639@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox