Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XtgXX-0007VM-0i for pgsql-sql@arkaria.postgresql.org; Wed, 26 Nov 2014 17:38:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XtgXW-0006nw-HJ for pgsql-sql@arkaria.postgresql.org; Wed, 26 Nov 2014 17:38:06 +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 1XtgXV-0006np-G6 for pgsql-sql@postgresql.org; Wed, 26 Nov 2014 17:38:05 +0000 Received: from [162.253.133.43] (helo=mwork.nabble.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XtgXN-00015e-Uv for pgsql-sql@postgresql.org; Wed, 26 Nov 2014 17:38:03 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mwork.nabble.com (Postfix) with ESMTP id 27B5EB5D80F for ; Wed, 26 Nov 2014 09:37:58 -0800 (PST) Date: Wed, 26 Nov 2014 10:37:57 -0700 (MST) From: Ron256 To: pgsql-sql@postgresql.org Message-ID: <1417023477345-5828381.post@n5.nabble.com> In-Reply-To: <1417012543637-5828331.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> 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: 1.9 (+) 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, Please I need your help on getting the first time buyer. I am using the following query but I am getting incorrect results with cte as (select *, row_number() OVER( partition by persistent_key_str order by ord_submitted_date) RN from orders ) select * from cte where rn = 1 When you use this persistent_key_str = '01000217334' I get incorrect results. How can I resolve this? Thanks, Ron -- View this message in context: http://postgresql.nabble.com/generating-the-average-6-months-spend-excluding-first-orders-tp5828253p5828381.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