Query to get Contract which is not had request raised from past three months and support plan remaining allowance for incident based plan

Query to get Contract which is not had request raised from past three months and support plan remaining allowance for incident based plan

Version : 11027
DB : PGSQL

OUTPUT:




SELECT ad.ORG_NAME AS "Account",
max(wo.workorderid) AS "Request ID",
longtodate(max(wo.createdtime)) AS "Request Created Time",
comp.COMPONENTNAME AS "Product",
ac.CONTRACTNAME AS "Contract Name",
ac.ISACTIVECONTRACT AS "Is Active Contract",
sp.SERVICEPLANNAME AS "Support Plan",
CASE WHEN (sp.fixedmonthlyunits - bc.consumedunits) > 0 THEN (sp.fixedmonthlyunits - bc.consumedunits) ELSE 0 END as "Total remaining Allowances"  FROM AccountContract ac
LEFT JOIN ServicePlan sp ON ac.SERVICEPLANID=sp.SERVICEPLANID
LEFT JOIN AccountDefinition ad ON ac.ACCOUNTID=ad.ORG_ID
LEFT JOIN WorkorderToContract wocon ON ac.contractid = wocon.contractid
left join billcycle bc on bc.contractid=ac.contractid
Left JOIN workorder wo on wocon.workorderid = wo.workorderid
LEFT JOIN WorkOrder_product wop ON wo.WORKORDERID=wop.WORKORDERID
 LEFT JOIN componentdefinition comp ON wop.product_id=comp.COMPONENTID
where  extract(epoch from( to_timestamp(wo.createdtime/1000)::TIMESTAMP - now()::TIMESTAMP))/3600/24 >=90 and ac.ISACTIVECONTRACT = true and sp.plantype = 'Charge Per Incident'
group by ad.org_name,ac.CONTRACTNAME,ac.ISACTIVECONTRACT,sp.SERVICEPLANNAME,sp.fixedmonthlyunits,bc.consumedunits,comp.COMPONENTNAME

                New to ADSelfService Plus?