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 A8C199FB1F0 for ; Sun, 9 Jul 2006 09:42:06 -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 33361-03 for ; Sun, 9 Jul 2006 09:41:57 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sapo.pt (relay3.ptmail.sapo.pt [212.55.154.23]) by postgresql.org (Postfix) with SMTP id 8D7BF9FA634 for ; Sun, 9 Jul 2006 09:41:56 -0300 (ADT) Received: (qmail 28395 invoked from network); 9 Jul 2006 12:41:52 -0000 Received: from unknown (HELO sapo.pt) (10.134.35.158) by relay3 with SMTP; 9 Jul 2006 12:41:52 -0000 Received: (qmail 23078 invoked from network); 9 Jul 2006 12:41:53 -0000 X-AntiVirus: PTMail-AV 0.3-0.88.2 X-Virus-Status: Clean (0.00519 seconds) Received: from unknown (HELO hmv02) (hmv@[82.155.154.115]) (envelope-sender ) by mta8 (qmail-ldap-1.03) with SMTP for ; 9 Jul 2006 12:41:53 -0000 Message-ID: <000f01c6a355$0dbf8240$6200a8c0@hmv02> From: =?iso-8859-1?Q?H=E9lder_M._Vieira?= To: References: <5644020.1152434024188.JavaMail.mbobi@mac.com> Subject: Re: distinct with sum Date: Sun, 9 Jul 2006 13:41:52 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/140 X-Sequence-Number: 25714 >I need to list products from the table of ordered products with ordered >quantities. Each product should be there only once but quantity should be a >sum from all the same products from the table. > I prepared some query but in quantity column I can see only amount from > one record. I need to have sum there. > > The query: > select distinct on (id_prod) id_prod, id_unit, sum(quantity) as result > from products where determinant = false group by id_prod, id_unit select id_prod, id_unit, sum(quantity) as result from products where determinant = false group by id_prod, id_unit Hélder M. Vieira