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)
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 ...