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 EE84D9FA6B2 for ; Sun, 9 Jul 2006 05:33:48 -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 93898-10 for ; Sun, 9 Jul 2006 05:33:46 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpout.mac.com (smtpout.mac.com [17.250.248.47]) by postgresql.org (Postfix) with ESMTP id 05EDE9FA66C for ; Sun, 9 Jul 2006 05:33:45 -0300 (ADT) Received: from mac.com (webmail01-en1 [10.13.11.143]) by smtpout.mac.com (Xserve/8.12.11/smtpout09/MantshX 4.0) with ESMTP id k698XifL020572 for ; Sun, 9 Jul 2006 01:33:44 -0700 (PDT) Received: from webmail01 (localhost [127.0.0.1]) by mac.com (Xserve/webmail01/MantshX 4.0) with ESMTP id k698Xicg009365 for ; Sun, 9 Jul 2006 01:33:44 -0700 (PDT) Received: from [83.5.20.97] by webmail.mac.com with HTTP; Sun, 09 Jul 2006 10:33:44 +0200 Message-ID: <5644020.1152434024188.JavaMail.mbobi@mac.com> Date: Sun, 09 Jul 2006 10:33:44 +0200 From: mbobi@mac.com To: pgsql-sql@postgresql.org Subject: distinct with sum MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Originating-IP: 83.5.20.97/instID=11 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/139 X-Sequence-Number: 25713 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 Thanks in advance for your help.