how to effectively SELECT new "customers"

From: Jan Ostrochovsky <ostrochovsky(at)mobiletech(dot)sk>
To: pgsql-sql(at)postgresql(dot)org
Subject: how to effectively SELECT new "customers"
Date: 2014-02-27 14:20:18
Message-ID: 1001132708.567696.1393510818245.JavaMail.root@mobiletech.sk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello, I am solving following task and it seems hard to me to find effective solution. Maybe somebody knows how to help me: We have table "purchases" and each one record is identified by "customer_id". We want to know not only how many different customers did at least one purchase per time period, grouped by time periods (easy task: "COUNT(DISTINCT customer_id)" with "GROUP BY period"), but also to know how many NEW customers there were. We define new customer as customer_id, which had first record in table "purchases" after 12 month of inactivity (no record in table "purchases" previous 12 months). I have found one solution, but it is very slow and ugly. I tried several other concepts, but without success. Any hint could be helpful for me. Thanks in advance! Jano

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2014-02-27 14:32:59 Re: Function Issue
Previous Message ALMA TAHIR 2014-02-27 12:23:12 Function Issue