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 D89A79FA64B for ; Tue, 25 Jul 2006 12:01: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 51316-10 for ; Tue, 25 Jul 2006 12:00:41 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.185]) by postgresql.org (Postfix) with ESMTP id 1BA3B9FA4E0 for ; Tue, 25 Jul 2006 12:00:39 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id p77so246776nfc for ; Tue, 25 Jul 2006 08:00:35 -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=abPBjAPQbB2JytndgAgPNB/2VJFcKABiNZaLa2jRoBRT6ltR0ABPtXsLH9HoKjGVO+bj7zDnUYMWP84jjtM7pFnGuU/g4mUf1+QRK707+c3dbsEpwm79KsyJfz/UT3RHikVi3/sbDqig/mrv893zbBsWUkOPoB9V5M3QxSCrvxY= Received: by 10.78.167.12 with SMTP id p12mr2355155hue; Tue, 25 Jul 2006 08:00:35 -0700 (PDT) Received: by 10.78.32.10 with HTTP; Tue, 25 Jul 2006 08:00:34 -0700 (PDT) Message-ID: Date: Tue, 25 Jul 2006 10:00:35 -0500 From: "Aaron Bono" To: "Otniel Michael" Subject: Re: About Div Cc: pgsql-sql@postgresql.org In-Reply-To: <20060725075726.47735.qmail@web53211.mail.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_145971_19326856.1153839635004" References: <20060725075726.47735.qmail@web53211.mail.yahoo.com> X-Google-Sender-Auth: e025d22f0178c817 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.599 tagged_above=0 required=5 tests=AWL, HTML_50_60, HTML_MESSAGE, SPF_PASS X-Spam-Level: X-Archive-Number: 200607/307 X-Sequence-Number: 25881 ------=_Part_145971_19326856.1153839635004 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/25/06, Otniel Michael wrote: > > Dear All, > > I have a problem with this case : > > I have 10 candy for 7 child (A, B, C, D, E, F, G). > > Table X : > code value > ------- -------- > A 0 > B 0 > C 0 > D 0 > E 0 > F 0 > G 0 > > And I want divide it with this algorithm : > A = 10 / 7 = 1 > B = (10-1) / (7-1) = 9 / 6 = 1 > C = (10-2) / (7-2) = 8 / 5 = 1 > D = (10-3) / (7-3) = 7 / 4 = 1 > E = (10-4) / (7-4) = 6 / 3 = 2 > F = (10-6) / (7-5) = 4 / 2 = 2 > G = (10-8) / (7-6) = 2 / 2 = 2 > > In my first solution i use loop - for each record in my function. > But it is too slow in a lot of data. > Did postgresql have a function for my case? > No loop necessary. This is a simple math problem: dividedamount := candy / childcount; extra = candy % childcount; So the first (childcount - extra) get (dividedamount) pieces of candy and the last (extra) get (dividedamount + 1) pieces of candy. ================================================================== Aaron Bono Aranya Software Technologies, Inc. http://www.aranya.com ================================================================== ------=_Part_145971_19326856.1153839635004 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/25/06, Otniel Michael <otmic_ie@yahoo.com> wrote:
Dear All,

I have a problem with this case :

I have 10 candy for 7 child (A, B, C, D, E, F, G).

Table X :
code   value
 -------  --------
 A        0       
 B        0       
 C        0       
 D        0       
 E        0       
 F        0       
 G       0       

And I want divide it with this algorithm :
    A = 10 / 7 = 1
    B = (10-1) / (7-1) = 9 / 6 = 1
    C = (10-2) / (7-2) = 8 / 5 = 1
    D = (10-3) / (7-3) = 7 / 4 = 1
    E = (10-4) / (7-4) = 6 / 3 = 2
    F = (10-6) / (7-5) = 4 / 2 = 2
    G = (10-8) / (7-6) = 2 / 2 = 2

In my first solution i use loop - for each record in my function.
But it is too slow in a lot of data.
Did postgresql have a function for my case?

 
No loop necessary.  This is a simple math problem:

dividedamount := candy / childcount;
extra = candy % childcount;

So the first (childcount - extra) get (dividedamount) pieces of candy and the last (extra) get (dividedamount + 1) pieces of candy.

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
================================================================== ------=_Part_145971_19326856.1153839635004--