how to effectively SELECT new "customers"

Поиск
Список
Период
Сортировка
От Jan Ostrochovsky
Тема how to effectively SELECT new "customers"
Дата
Msg-id 1001132708.567696.1393510818245.JavaMail.root@mobiletech.sk
обсуждение исходный текст
Ответы Re: how to effectively SELECT new "customers"
Список 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

В списке pgsql-sql по дате отправления: