Tested in Build PGSQL (14300)
PGSQL:
select wo.workorderid as "RequestID", wo.Title as "Title", reqaaa.First_Name as "Requester", aaa.first_name as "Technician", sd.StatusName as "Status", wo.CreatedTime as "CreatedTime", wos.AssignedTime as "AssignedTime", wo.DueByTime as "DueByTime", woh.operationtime as "LastUpdatedTime", aaa2.first_name as "LastUpdateBy", cd.CategoryName as "CategoryName", scd.name as "SubCategoryName", (CAST(EXTRACT(EPOCH FROM now()) * 1000 AS BIGINT)-wo.createdtime)/1000/3600/24 "Aging Day(s)" from workorder "wo" left join workorderstates "wos" on wo.workorderid=wos.workorderid left join sduser "reqsu" on wo.requesterid=reqsu.userid left join aaauser "reqaaa" on reqsu.userid=reqaaa.user_id left join statusdefinition "sd" on wos.statusid=sd.statusid left join sduser "su" on wos.ownerid=su.userid left join aaauser "aaa" on su.userid=aaa.user_id left join prioritydefinition "pd" on wos.priorityid=pd.priorityid left join categorydefinition "cd" on wos.categoryid=cd.categoryid left join subcategorydefinition "scd" on wos.subcategoryid=scd.subcategoryid left join accountsitemapping "asm" on asm.siteid=wo.siteid left join (select woh1.workorderid, woh1.operationownerid, woh1,operationtime from workorderhistory "woh1" left join (select woh3.workorderid, max(woh3.operationtime) as "maxoperationtime" from workorderhistory "woh3" group by woh3.workorderid) as "woh2" on woh1.workorderid=woh2.workorderid where woh1.operationtime=woh2.maxoperationtime) as "woh" on woh.workorderid=wo.workorderid left join aaauser "aaa2" on woh.operationownerid=aaa2.user_id where wo.ISPARENT='1' and sd.statusname<>'Closed' and sd.statusname<>'Resolved' and (CAST(EXTRACT(EPOCH FROM now()) * 1000 AS BIGINT)-wo.createdtime)/1000/3600/24 > 7