0

I want to use max_by(event_id, date_created) twice: once when date_created<= first_upgrade_date one once when date_created<= prediction_point is there a way to do that in one query instead of two (in each one using different condition in where)

1 Answers1

0

Use filtered aggregations. Example:

SELECT
  max_by(event_id, date_created) FILTER (WHERE date_created <= first_upgrade_date),
  max_by(event_id, date_created) FILTER (WHERE date_created <= prediction_point)
FROM ...
Piotr Findeisen
  • 19,480
  • 2
  • 52
  • 82