0

I have records with values like: date, hour, value. Aggregating whole day is easy, i just group by date. My problem is that i need to aggregate records from whole days with specific start/end time. In example when start time is 9 a.m. then i have records: - from monday 9 a.m. to tuesday 8 a.m (grouped in one record) - from tuesday 9 a.m. to wednesday 8 a.m. (grouped in one record) and so on. Thanks, for any ideas.

2 Answers 2

2

I'm going to assume your hour field is an INT, but regardless you should be able to adapt this...

GROUP BY
  CASE WHEN hour >= 9 THEN date ELSE date - 1 END

This essentially treats any hour before 9am as being part of the previous day.

Sign up to request clarification or add additional context in comments.

Comments

0

GROUP BY date_trunc('day',date+(hour-9)*interval '1h') or something like that?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.