I have a lovely little CTE/select doing exactly what I need it to do. Unfortunately I need its results in the next query.
pgsql-sql by date:
Соглашаюсь с условиями обработки персональных данных