I need to have a report with calculation of some values from different tables. I\'m using CTE and subquery for calculations but the query is slow. I tried a few