MSSQL
SELECT wo.workorderid AS "Request ID", ad.org_name AS "Account", wo.helpdeskid AS "portalID" FROM workorder wo
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN AccountSiteMapping asm ON wo.SITEID=asm.SITEID
LEFT JOIN AccountDefinition ad ON asm.ACCOUNTID=ad.ORG_ID
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID
LEFT JOIN WorkOrderHistory woh ON wo.WORKORDERID = woh.WORKORDERID
LEFT JOIN WorkOrderHistoryDiff wohd ON woh.HISTORYID = wohd.HISTORYID
WHERE (wo.ISPARENT='1') and std.statusname='Resolved'
and wohd.COLUMNNAME in ('STATUSID')
group by wo.WORKORDERID,ad.org_name having DATEDIFF(day, dateadd(s,datediff(s,GETUTCDATE() ,getdate()) +(max(woh.OPERATIONTIME)/1000),'1970-01-01 00:00:00'),GETDATE()) > 30
PGSQL
SELECT wo.workorderid AS "Request ID", ad.org_name AS "Account", wo.helpdeskid AS "portalID" FROM workorder wo
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN AccountSiteMapping asm ON wo.SITEID=asm.SITEID
LEFT JOIN AccountDefinition ad ON asm.ACCOUNTID=ad.ORG_ID
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID
LEFT JOIN WorkOrderHistory woh ON wo.WORKORDERID = woh.WORKORDERID
LEFT JOIN WorkOrderHistoryDiff wohd ON woh.HISTORYID = wohd.HISTORYID
WHERE (wo.ISPARENT='1') and std.statusname='Resolved'
and wohd.COLUMNNAME in ('STATUSID')
group by wo.WORKORDERID,ad.org_name having extract(epoch from(now()::TIMESTAMP - to_timestamp(max(woh.OPERATIONTIME)/1000)::TIMESTAMP))/3600/24 > 30