Partition over a sliding date window

Поиск
Список
Период
Сортировка
От Guillaume Roger
Тема Partition over a sliding date window
Дата
Msg-id 4E6F3DB3.4030905@spilgames.com
обсуждение исходный текст
Список pgsql-sql
Hi,

I have a simple table with 3 fields: date, value and username, which can 
hold identical rows.

What I am trying to do is to have for each date the count of distinct 
username for the 30 previous days.

I was hoping to get this with a partition, as in the following 
non-working exemple

SELECT    t.date  , t.value  , COUNT(DISTINCT t.username) OVER (PARTITION date BETWEEN t.date - 
INTERVAL '29 days' and t.date)
FROM  table t
GROUP BY    date  , value  , username
;

There are many issues with this query:
- distinct not implemented for window function
- COUNT () OVER is not seen as an aggregate function, I thus need to add 
username in the GROUP BY clause, which leads to wrong result
- I am not convinced that the date BETWEEN is valid either, but the 
other issues prevent me to check this.

Is there a way to do what I am looking for with partitions, or should I 
just give up and use 'usual' sql?

Thanks,
Guillaume


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

Предыдущее
От: Samuel Gendler
Дата:
Сообщение: Re: Use select and update together
Следующее
От: Dianna Harter
Дата:
Сообщение: Window function sort order help