Thank you all! My problem has been solved in another way... because the inner queries had left outer joins and so on, and I finally have had to do two queries and treat results by PHP. Again... thank you all!
pgsql-sql by date:
Соглашаюсь с условиями обработки персональных данных