X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7595353707 for ; Mon, 4 Apr 2005 11:58:23 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63939-04 for ; Mon, 4 Apr 2005 10:58:19 +0000 (GMT) Received: from quasar.skima.is (quasar.skima.is [212.30.200.205]) by svr1.postgresql.org (Postfix) with ESMTP id B382A536A2 for ; Mon, 4 Apr 2005 11:58:18 +0100 (BST) Received: from gnari ([157.157.159.208] [157.157.159.208]) by quasar.skima.is with ESMTP; Mon, 4 Apr 2005 10:58:21 Z Subject: Re: select & group by From: Ragnar =?ISO-8859-1?Q?Hafsta=F0?= To: "Michael L. Hostbaek" Cc: pgsql-sql@postgresql.org In-Reply-To: <1112611630.19933.6.camel@localhost.localdomain> References: <20050404101647.GJ23648@mich2.itxmarket.com> <1112611630.19933.6.camel@localhost.localdomain> Content-Type: text/plain; charset=iso-8859-1 Date: Mon, 04 Apr 2005 10:59:15 +0000 Message-Id: <1112612355.19933.12.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/43 X-Sequence-Number: 20936 On Mon, 2005-04-04 at 10:47 +0000, Ragnar Hafstaš wrote: > On Mon, 2005-04-04 at 12:16 +0200, Michael L. Hostbaek wrote: > > [problem] > [slightly broken solution] I forgot a FROM clause, and you might want to add a ORDER BY clause, if that is important: select part,mfg, sum(CASE WHEN eta is NULL then qty ELSE 0 END) as qty, sum(CASE WHEN eta is NULL then 0 ELSE qty END) as "qty incoming", max(price) as "highest price", min(eta) as eta from thetable group by part,mfg order by part,mfg; gnari