Skip to content
Advertisement

GROUP by data by time range in postgresql

I want to GROUP by data by time range. The example I have start_date and end_date, and I want the separate range between start_date and end_date on 25 range and get sum value from 1 to 25.

Simple presentation of my table:

table t1 have:

generate_series function to separate on

and sum by how this 25

for 2019-10-01 to have value 100 for 2019-10-02 to have value 400

Advertisement

Answer

I am going to recommend a lateral join:

A lateral join can have better performance than overall aggregation, particularly with an index on (time, value).

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement