Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xu7ti-0003ao-90 for pgsql-sql@arkaria.postgresql.org; Thu, 27 Nov 2014 22:50:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xu7th-0003WN-1x for pgsql-sql@arkaria.postgresql.org; Thu, 27 Nov 2014 22:50:49 +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 1XtiEL-0003UN-K9 for pgsql-sql@postgresql.org; Wed, 26 Nov 2014 19:26:25 +0000 Received: from [162.253.133.43] (helo=mwork.nabble.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XtiEH-0004tK-Sb for pgsql-sql@postgresql.org; Wed, 26 Nov 2014 19:26:24 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mwork.nabble.com (Postfix) with ESMTP id 47D5FB5FF77 for ; Wed, 26 Nov 2014 11:26:21 -0800 (PST) Date: Wed, 26 Nov 2014 12:26:20 -0700 (MST) From: Ron256 To: pgsql-sql@postgresql.org Message-ID: <1417029980347-5828407.post@n5.nabble.com> In-Reply-To: <1417026875109-5828394.post@n5.nabble.com> References: <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> <1417026875109-5828394.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 have modified the first query to my needs and I believe, it gives the correct results for the first time orders. accept 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 AND o.ord_submitted_date = c.ord_date Thanks for your support. Thanks, Ron -- View this message in context: http://postgresql.nabble.com/generating-the-average-6-months-spend-excluding-first-orders-tp5828253p5828407.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