在PostgresSQL中处理日期

我正在尝试将要查询的列表天数转换为下面列出的查询中的几周

请告知。谢谢您的帮助。

zhenyuting 回答:在PostgresSQL中处理日期

您可以先在子查询中按date_trunc('week',...)进行聚合,然后在外部查询中计算相邻行之间的增量:

select 
    anchor,average,100.000 * (1 - lead(average) over (order by anchor) / average) as delta
from (
    select 
        date_trunc('week',day) anchor,round(avg(value)) average
    from mytable
    group by date_trunc('week',day)
) t
order by anchor
本文链接:https://www.f2er.com/3168823.html

大家都在问