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 E58E8533CB for ; Mon, 4 Apr 2005 13:23:36 +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 87590-06 for ; Mon, 4 Apr 2005 12:23:32 +0000 (GMT) Received: from mail2.itxmarket.com (fw.itxmarket.com [213.11.40.109]) by svr1.postgresql.org (Postfix) with ESMTP id E84D3533C2 for ; Mon, 4 Apr 2005 13:23:30 +0100 (BST) Received: from icommerce.fr (mich2.itxmarket.com [192.168.2.26]) by mail2.itxmarket.com (Postfix) with ESMTP id 3450B1C091F; Mon, 4 Apr 2005 14:23:34 +0200 (CEST) Received: by icommerce.fr (Postfix, from userid 1001) id 1E2E022825; Mon, 4 Apr 2005 14:23:34 +0200 (CEST) Date: Mon, 4 Apr 2005 14:23:34 +0200 From: "Michael L. Hostbaek" To: Ragnar =?iso-8859-1?Q?Hafsta=F0?= Cc: pgsql-sql@postgresql.org Subject: Re: select & group by Message-ID: <20050404122334.GM23648@mich2.itxmarket.com> Mail-Followup-To: "Michael L. Hostbaek" , Ragnar =?iso-8859-1?Q?Hafsta=F0?= , pgsql-sql@postgresql.org References: <20050404101647.GJ23648@mich2.itxmarket.com> <1112611630.19933.6.camel@localhost.localdomain> <1112612355.19933.12.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1112612355.19933.12.camel@localhost.localdomain> X-Operating-System: FreeBSD 5.3-STABLE i386 X-PGP-Key: http://www.freebsdcluster.org/~mich/ User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200504/44 X-Sequence-Number: 20937 Ragnar Hafstaš (gnari) writes: > 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; Thanks, this works brilliantlty ! /mich