Tested in Build PGSQL (14300)
Non Billable Requests pgsql
SELECT wo.workorderid "Request ID", wo.TITLE AS "Subject", longtodate(ct.CREATEDTIME) AS "Time Spent Created Time", rctd.FIRST_NAME AS "Time Spent Technician", TO_CHAR((sum(ct.TIMESPENT)/1000 || ' second')::interval, 'HH24:MI:SS') "TimeSpent" FROM WorkOrder wo LEFT JOIN WorkOrderToCharge wotoc ON wo.WORKORDERID=wotoc.WORKORDERID LEFT JOIN ChargesTable ct ON wotoc.CHARGEID=ct.CHARGEID LEFT JOIN SDUser rcti ON ct.TECHNICIANID=rcti.USERID LEFT JOIN AaaUser rctd ON rcti.USERID=rctd.USER_ID INNER JOIN AccountSiteMapping asm ON wo.siteid=asm.siteid INNER JOIN AccountDefinition ad ON asm.accountid=ad.org_id INNER JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN NonBillableRequests nbr ON wo.workorderid=nbr.requestid LEFT JOIN nobillrequestcharges NBRC ON ct.chargeid=nbrc.requestchargeid WHERE ct.createdtime>=DATETOLONG('2015-01-03 07:00:00') and ct.createdtime<=DATETOLONG('2018-01-03 16:00:00') and ad.ORG_NAME = 'PINNACLE' AND nbrc.requestchargeid is not null group by 1,3,4 order by 1
Billable Requests pgsql
SELECT wotoc.workorderid "Request ID", wo.TITLE AS "Subject", longtodate(ct.CREATEDTIME) AS "Time Spent Created Time", rctd.FIRST_NAME AS "Time Spent Technician", TO_CHAR((sum(ct.TIMESPENT)/1000 || ' second')::interval, 'HH24:MI:SS') "TimeSpent" FROM WorkOrder wo LEFT JOIN WorkOrderToCharge wotoc ON wo.WORKORDERID=wotoc.WORKORDERID LEFT JOIN worklogcharges wc ON wotoc.CHARGEID=wc.requestchargeid LEFT JOIN ChargesTable ct ON ct.chargeid=wc.requestchargeid LEFT JOIN SDUser rcti ON ct.TECHNICIANID=rcti.USERID LEFT JOIN AaaUser rctd ON rcti.USERID=rctd.USER_ID INNER JOIN AccountSiteMapping asm ON wo.siteid=asm.siteid INNER JOIN AccountDefinition ad ON asm.accountid=ad.org_id INNER JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID WHERE ct.createdtime>=DATETOLONG('2015-01-03 07:00:00') and ct.createdtime<=DATETOLONG('2018-01-03 16:00:00') and ct.chargeid=wc.requestchargeID and ad.ORG_NAME = 'PINNACLE' group by 1,2,3,4 order by 1