Hello, I've got a quite big query in our project, which works very slow if the database is big. So I'm looking for the ways to optimize it. As you can see most of nested selects are pretty similar except small details. May be it's possible to merge them or something like else? I think the biggest problem is joins in each select.
Here is the query.
Hope you can give me some advice how to optimize it. Thanks.
[upd] I'm using postgesql db, the query in plsql language looks like this