Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XthQG-0001QO-K4 for pgsql-sql@arkaria.postgresql.org; Wed, 26 Nov 2014 18:34:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XthQG-0002mh-01 for pgsql-sql@arkaria.postgresql.org; Wed, 26 Nov 2014 18:34:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XthQE-0002ma-Ur for pgsql-sql@postgresql.org; Wed, 26 Nov 2014 18:34:39 +0000 Received: from [162.253.133.43] (helo=mwork.nabble.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XthQB-00029T-GW for pgsql-sql@postgresql.org; Wed, 26 Nov 2014 18:34:37 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mwork.nabble.com (Postfix) with ESMTP id F2C8BB5EE65 for ; Wed, 26 Nov 2014 10:34:35 -0800 (PST) Date: Wed, 26 Nov 2014 11:34:35 -0700 (MST) From: Ron256 To: pgsql-sql@postgresql.org Message-ID: <1417026875109-5828394.post@n5.nabble.com> In-Reply-To: <1417026089049-5828392.post@n5.nabble.com> References: <1416970805198-5828253.post@n5.nabble.com> <1416974013524-5828256.post@n5.nabble.com> <1416977793450-5828259.post@n5.nabble.com> <1417012543637-5828331.post@n5.nabble.com> <1417023477345-5828381.post@n5.nabble.com> <1417024519548-5828385.post@n5.nabble.com> <1417025960949-5828390.post@n5.nabble.com> <1417026089049-5828392.post@n5.nabble.com> Subject: Re: generating the average 6 months spend excluding first orders MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 162.253.133.43 (failed) X-Pg-Spam-Score: 0.5 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Using the following query, SELECT o.persistent_key_str, o.ord_id FROM orders o WHERE o.ord_submitted_date in ( SELECT min(ord_submitted_date)ord_date FROM orders group by persistent_key_str) I was able to generate the following output: The customer who placed two orders on the same date also appears in the result set. Thanks, Ron -- View this message in context: http://postgresql.nabble.com/generating-the-average-6-months-spend-excluding-first-orders-tp5828253p5828394.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql