pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aaron Bono <postgresql@aranya.com>
To: Phillip Smith <phillips@weatherbeeta.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: Select Maths
Date: Fri, 7 Jul 2006 03:36:53 -0500
Message-ID: <bf05e51c0607070136he5519b9x96e97a73a6483a2a@mail.gmail.com> (raw)
In-Reply-To: <012b01c6a192$1b827730$9b0014ac@ITPhil>
References: <012b01c6a192$1b827730$9b0014ac@ITPhil>

On 7/7/06, Phillip Smith <phillips@weatherbeeta.com.au> wrote:
>
> Same SELECT query as before, different area of it… I have a function that
> calculates the recommended purchase order quantity for a stock item based
> off various other values and functions:
>
> pqty(stock.code) AS "pqty"
>
>
>
> This needs to be rounded up / down to the nearest multiple of the *purchase
> unit* quantity for that product – It's Friday afternoon and my head has
> refused to help me work out the maths all afternoon!
>
>
>
> Example:
>
>      Pqty = 60
>
>      Purchase Unit = 25
>
> Pqty needs to be rounded down to 50.
>
>
>
> I guess I'm also asking if I should do this in the Pqty function or in the
> SELECT query to optimize the result?
>

select 25 * round(cast(60 as double precision) / 25)

view thread (8+ messages)  latest in thread

Message-ID: <bf05e51c0607070136he5519b9x96e97a73a6483a2a@mail.gmail.com>
Permalink:  ../bf05e51c0607070136he5519b9x96e97a73a6483a2a@mail.gmail.com/
Also on:    postgresql.org/message-id/bf05e51c0607070136he5519b9x96e97a73a6483a2a@mail.gmail.com

 · 

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: postgresql@aranya.com, phillips@weatherbeeta.com.au
  Subject: Re: Select Maths
  In-Reply-To: <bf05e51c0607070136he5519b9x96e97a73a6483a2a@mail.gmail.com>

* 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