agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Jan Ostrochovsky <ostrochovsky@mobiletech.sk>
To: pgsql-sql@postgresql.org
Subject: how to effectively SELECT new "customers"
Date: Thu, 27 Feb 2014 15:20:18 +0100 (CET)
Message-ID: <1001132708.567696.1393510818245.JavaMail.root@mobiletech.sk> (raw)
In-Reply-To: <883409020.566998.1393509966607.JavaMail.root@mobiletech.sk>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
view thread (10+ messages) latest in thread
Message-ID: <1001132708.567696.1393510818245.JavaMail.root@mobiletech.sk>
Permalink: ../1001132708.567696.1393510818245.JavaMail.root@mobiletech.sk/
Also on: postgresql.org/message-id/1001132708.567696.1393510818245.JavaMail.root@mobiletech.sk
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: ostrochovsky@mobiletech.sk
Subject: Re: how to effectively SELECT new "customers"
In-Reply-To: <1001132708.567696.1393510818245.JavaMail.root@mobiletech.sk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox