Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XtgoL-0008KE-PY for pgsql-sql@arkaria.postgresql.org; Wed, 26 Nov 2014 17:55:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XtgoL-0004Kq-5p for pgsql-sql@arkaria.postgresql.org; Wed, 26 Nov 2014 17:55:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XtgoK-0004Kj-5k for pgsql-sql@postgresql.org; Wed, 26 Nov 2014 17:55:28 +0000 Received: from [162.253.133.43] (helo=mwork.nabble.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XtgoC-00039q-9u for pgsql-sql@postgresql.org; Wed, 26 Nov 2014 17:55:26 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mwork.nabble.com (Postfix) with ESMTP id 5E5F9B5DF18 for ; Wed, 26 Nov 2014 09:55:20 -0800 (PST) Date: Wed, 26 Nov 2014 10:55:19 -0700 (MST) From: Ron256 To: pgsql-sql@postgresql.org Message-ID: <1417024519548-5828385.post@n5.nabble.com> In-Reply-To: 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> 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 David, I made a few changes to my query and looks like I am moving in the right direction I have also attached my output. WITH first_cust_cte AS ( SELECT min(ord_submitted_date)ord_date , persistent_key_str FROM orders group by persistent_key_str ) SELECT o.persistent_key_str, o.ord_id FROM orders o INNER JOIN first_cust_cte c ON o.persistent_key_str = c.persistent_key_str WHERE ord_submitted_date = ord_date Thanks, Ron -- View this message in context: http://postgresql.nabble.com/generating-the-average-6-months-spend-excluding-first-orders-tp5828253p5828385.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