Re: Select Maths - Mailing list pgsql-sql

From Aaron Bono
Subject Re: Select Maths
Date
Msg-id bf05e51c0607070136he5519b9x96e97a73a6483a2a@mail.gmail.com
Whole thread Raw
In response to Select Maths  ("Phillip Smith" <phillips@weatherbeeta.com.au>)
Responses Re: Select Maths
List pgsql-sql
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)

pgsql-sql by date:

Previous
From: "Aaron Bono"
Date:
Subject: Re: Alternative to serial primary key
Next
From: "Aaron Bono"
Date:
Subject: Re: Select CASE Concatenation