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 0796B563EB for ; Mon, 14 Mar 2005 08:58:19 +0000 (GMT) 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 34717-02 for ; Mon, 14 Mar 2005 08:58:11 +0000 (GMT) Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10]) by svr1.postgresql.org (Postfix) with ESMTP id D735756381 for ; Mon, 14 Mar 2005 08:58:10 +0000 (GMT) Received: (qmail 23293 invoked from network); 14 Mar 2005 09:58:14 +0100 Received: from unknown (HELO localhost) (boutiquenumerique-lists@192.168.0.4) by boutiquenumerique.com with SMTP; 14 Mar 2005 09:58:14 +0100 To: "Sim Zacks" , pgsql-sql@postgresql.org Subject: Re: group by before and after date References: Message-ID: Date: Mon, 14 Mar 2005 09:58:10 +0100 From: PFC Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Opera M2/7.54 (Linux, build 955) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/191 X-Sequence-Number: 20670 > I have 2 tables 1 has a date field and component need by that date and > the > other has all the upcoming orders. > I am trying to build a query that will give me the Date and ComponentNeed > and also how many components have been ordered before that date and how > many > after. > PostGreSQL is telling me I need to group on DatePromisedBy. I have tried > a > number of different possibilities which haven't worked and now I have run > into brain freeze. Any help would be appreciated. You could : SELECT ..., sum( stuff ), ..., (DatePromisedBy > a_particular_date) as after GROUP BY after You'll get two lines, one the sum of things before a_particular_date, one of things after a_particular_date. Look in the 'after' field to know which is which.