From: | David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: generating the average 6 months spend excluding first orders |
Date: | 2014-11-26 18:04:41 |
Message-ID: | CAKFQuwafwdV3uqWgFy-ChXtdCO46WG+96yM2TCf9y4NBZGNOew@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, Nov 26, 2014 at 10:55 AM, Ron256 [via PostgreSQL] <
ml-node+s1045698n5828385h59(at)n5(dot)nabble(dot)com> 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_date[image: My 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: http://postgresql.nabble.com/generating-the-average-6-months-spend-excluding-first-orders-tp5828253p5828386.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Ron256 | 2014-11-26 18:19:20 | Re: generating the average 6 months spend excluding first orders |
Previous Message | Ron256 | 2014-11-26 17:55:19 | Re: generating the average 6 months spend excluding first orders |