我需要按5天的增量将日期分组,而不是标准的date_trunc('week',date)
,以便对该分组进行count(*)
有人可以帮助我吗?
提前谢谢
答案 0 :(得分:1)
您将获得最短的日期,取差值并除以5:
select ( datediff(day, min_date, date) / 5 )::int as period_num,
count(*)
from (select t.*, min(date) over (order by date) as min_date
from t
) t
group by 1;