Re: generating the average 6 months spend excluding first orders - Mailing list pgsql-sql

From David G Johnston
Subject Re: generating the average 6 months spend excluding first orders
Date
Msg-id CAKFQuwafwdV3uqWgFy-ChXtdCO46WG+96yM2TCf9y4NBZGNOew@mail.gmail.com
Whole thread Raw
In response to Re: generating the average 6 months spend excluding first orders  (Ron256 <ejaluronaldlee@gmail.com>)
Responses Re: generating the average 6 months spend excluding first orders
List pgsql-sql
On Wed, Nov 26, 2014 at 10:55 AM, Ron256 [via PostgreSQL] <[hidden email]> wrote:

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_dateMy output

Thanks,

Ron

​Your query assumes that a person cannot place two orders on the same day - notes rows 3 & 4.  If the actual date field had second or smaller precision this will probably be OK...​

David J.



View this message in context: Re: generating the average 6 months spend excluding first orders
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

pgsql-sql by date:

Previous
From: Ron256
Date:
Subject: Re: generating the average 6 months spend excluding first orders
Next
From: Ron256
Date:
Subject: Re: generating the average 6 months spend excluding first orders