Query to find the difference between technician assigned and group assigned time (PGSQL)

Query to find the difference between technician assigned and group assigned time (PGSQL)

Tested in Build PGSQL (14300) 


Please go to Reports-New Query Report and execute this query.

SELECT wo.WORKORDERID "Request id", 
longtodate(min(ta.OPERATIONTIME)) "Technician assigned time", 
longtodate(min(gp.OPERATIONTIME)) "Group assigned time", 
TO_CHAR(((min(ta.OPERATIONTIME)-min(gp.OPERATIONTIME))/1000 || ' second')::interval, 'HH24:MI:SS')  "Time to assign" FROM WorkOrder wo  
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN CategoryDefinition cd ON wos.CATEGORYID=cd.CATEGORYID LEFT JOIN WorkOrder_Queue woq ON wo.WORKORDERID=woq.WORKORDERID LEFT JOIN QueueDefinition qd ON woq.QUEUEID=qd.QUEUEID  
LEFT JOIN (select woh.workorderid, woh.operationtime from workorderhistory woh left join workorderhistorydiff wohd on woh.historyid=wohd.historyid where wohd.columnname='OWNERID') ta on wo.workorderid=ta.workorderid 
LEFT JOIN (select woh1.workorderid, woh1.operationtime from workorderhistory woh1 left join workorderhistorydiff wohd1 on woh1.historyid=wohd1.historyid where wohd1.columnname='queueid') gp on wo.workorderid=gp.workorderid 
  WHERE (wo.ISPARENT='1') and wo.CREATEDTIME >= <from_thismonth> AND wo.CREATEDTIME <= <to_thismonth> group by wo.WORKORDERID  

PGSQL

                  New to ADSelfService Plus?