I have to finetune the below query in Postgres its taking time for fetching the data, can you help Me?

19 views Asked by At
select to_char(ts."SubmittedDate", 'YYYY-MM') as "monthYear",
       MIN(ts."TimeEntryID") as "TimeEntryID",
       SUM(ts."SpentTime") as "TotalHours",
       MAX(ts."CreatedOn") as "CreatedOn",
       ts."ApplicationID",
       ts."TSTypeCodeID",
       rcv."CodeName" as TSType,
       ts."UserID",
       ts."StatusID",
       st."Status"
from task_management_v1."TimeSheet" ts
   left join task_management_v1."Status" st
      on ts."StatusID" = st."ID"
   left join task_management_v1."RefCodeValue" rcv
      on ts."TSTypeCodeID" = rcv."CodeValueID"
   left join task_management_v1."Users" u
      on ts."ApplicationID" = u."ApplicationID" and ts."UserID" = u."UserID"
where ts."ApplicationID" = 34
  and ts."UserID" in ('YXR4318','KXL5356','BXB0448') 
  and ts."StatusID" in ( 47,44,45,46) 
  and ts."SubmittedDate" > CURRENT_DATE - INTERVAL '3 months' 
group by ts."UserID" , 
         ts."StatusID" , 
         ts."ApplicationID",
         1, 
         st."Status", 
         ts."TSTypeCodeID", 
         TSType
order by 4 desc
limit 25 offset 0;

I tried with a CTE, but I am getting duplicates.

0

There are 0 answers