X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 791209FA68D for ; Fri, 7 Jul 2006 05:37:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 38565-08 for ; Fri, 7 Jul 2006 05:36:55 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.191]) by postgresql.org (Postfix) with ESMTP id 39D209FA65C for ; Fri, 7 Jul 2006 05:36:54 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id n15so124989nfc for ; Fri, 07 Jul 2006 01:36:53 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=X01MiKZbRzwQi76m4iUhQm9NQ51Da0Qzv5ay7wNtD2q8owTwytBi/EHNWAHeWicp0xEtnh1V6I6StwErQkStLDF7FbKACvZMG1M/g0KrPraG8HKtNP6lRs8XLwPF24hMbQewyD5n0ryxVY5vw1hdObWxXvit/bzdJZJMUEHpkzQ= Received: by 10.78.157.15 with SMTP id f15mr566203hue; Fri, 07 Jul 2006 01:36:53 -0700 (PDT) Received: by 10.78.29.2 with HTTP; Fri, 7 Jul 2006 01:36:53 -0700 (PDT) Message-ID: Date: Fri, 7 Jul 2006 03:36:53 -0500 From: "Aaron Bono" To: "Phillip Smith" Subject: Re: Select Maths Cc: pgsql-sql@postgresql.org In-Reply-To: <012b01c6a192$1b827730$9b0014ac@ITPhil> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_106923_11841667.1152261413241" References: <012b01c6a192$1b827730$9b0014ac@ITPhil> X-Google-Sender-Auth: fd5b44d21b3c2a73 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/84 X-Sequence-Number: 25658 ------=_Part_106923_11841667.1152261413241 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 7/7/06, Phillip Smith wrote: > > Same SELECT query as before, different area of it=85 I have a function th= at > 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 *purcha= se > unit* quantity for that product =96 It's Friday afternoon and my head has > refused to help me work out the maths all afternoon! > > > > Example: > > Pqty =3D 60 > > Purchase Unit =3D 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 th= e > SELECT query to optimize the result? > select 25 * round(cast(60 as double precision) / 25) ------=_Part_106923_11841667.1152261413241 Content-Type: text/html; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 7/7/06, Phillip Smith <phillips@weatherbeeta.com.au> wr= ote:

Same SELECT query as before, different area of it=85 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 =96 It's Friday afternoon and my head has refused to help me work out the maths all afternoon!

 

Example:

     Pqty =3D 60

     Purchase Unit =3D 25

Pqty needs to be rounded down to 50.<= /font>

 

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)

------=_Part_106923_11841667.1152261413241--