Resample on time series data

2019-07-10 10:38发布

I have a table with time series column in the millisecond, I want to resample the time series and apply mean on the group. How can I implement it in Postgres?

"Resample" means aggregate all time stamps within one second or one minute. All rows within one second or one minute form a group.

table structure

date    x    y    z

1条回答
beautiful°
2楼-- · 2019-07-10 11:19

Use date_trunc() to truncate timestamps to a given unit of time, and GROUP BY that expression:

SELECT date_trunc('minute', date) AS date_truncated_to_minute
      ,avg(x) AS avg_x
      ,avg(y) AS avg_y
      ,avg(z) AS avg_z
FROM   tbl
GROUP  BY 1;

Assuming your misleadingly named date column is actually of type timestamp.

Related answer with more details and links:

查看更多
登录 后发表回答