Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A298A2E0035 for ; Mon, 19 Nov 2007 17:11:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 03544-04 for ; Mon, 19 Nov 2007 17:11:01 -0400 (AST) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.224]) by postgresql.org (Postfix) with ESMTP id BEF3F2E003B for ; Mon, 19 Nov 2007 17:11:40 -0400 (AST) Received: by wx-out-0506.google.com with SMTP id r21so94785wxc for ; Mon, 19 Nov 2007 13:11:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=b3fpJ0yT1RDvv5d0qtujh7s+ye8Z3mChHC7Gb2uBs3U=; b=lTv6fCnk+uuKSyxdMgITF1TLYbXP9j+jkyuetuRFgJgf5/Rn1G1ANFKdtcRERx6uS+r78hwQRPtfUz+/Ytkz6+ZXWyUHlkKj/Yw0+SLgCd8+oY1xgjMqI3KdfXwK/6RqepGdV0Ci6ZzP5AWPGkpE5PUQPCS/UVvKvrdSqZ+ibH0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=H/5UWAAbzsTVREWaH2bGpWm4Q2NA5s6Xpl9+qBavltDJXxIoPgHRDbVtJvPrhvObrs4FFbvX0Y2pyNx3TBwbrbLjw224/YQa//cFe/o0ixke6QNJTjSSaFElP1o+6s8QZ9Wpb9/uxenbHmjVBdZde4N5ucxBasxIf/dNBaFfeP4= Received: by 10.90.93.6 with SMTP id q6mr7474534agb.1195506699426; Mon, 19 Nov 2007 13:11:39 -0800 (PST) Received: by 10.90.120.17 with HTTP; Mon, 19 Nov 2007 13:11:39 -0800 (PST) Message-ID: Date: Mon, 19 Nov 2007 16:11:39 -0500 From: "=?UTF-8?Q?Rodrigo_De_Le=C3=B3n?=" To: "Luiz K. Matsumura" Subject: Re: Aggregate question (Sum) Cc: pgsql-sql@postgresql.org In-Reply-To: <4741F63A.6070500@planit.com.br> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4741F63A.6070500@planit.com.br> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/93 X-Sequence-Number: 29621 On Nov 19, 2007 3:46 PM, Luiz K. Matsumura wrote: > If someone can give me some hint I will apreciate. This is more of a normalization problem. See: http://www.deeptraining.com/litwin/dbdesign/FundamentalsOfRelationalDatabaseDesign.aspx and lookup Third Normal Form. You have a calculated total for each order, so I assume there's a price for every product. You should join order_item to whichever table has the individual cost for each product and multiply it by order_item.qty. Good luck.