Query to show tickets created based on shift time_PGSQL

Query to show tickets created based on shift time_PGSQL

Filter mentioned by converting into minutes.

PGSQL:

7.30 AM - 7.30 PM

SELECT wo.WORKORDERID AS "Request ID", pd.PRIORITYNAME AS "Priority", std.STATUSNAME AS "Request Status",
LONGTODATE(wo.CREATEDTIME) AS "Created Time",
extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "hh",
extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "minu",extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "total minutes"  FROM WorkOrder wo
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN PriorityDefinition pd ON wos.PRIORITYID=pd.PRIORITYID
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE wo.ISPARENT='1'  and
extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP)  > 558
and extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) < 1038

7.30 PM - 7.30 AM

SELECT wo.WORKORDERID AS "Request ID", pd.PRIORITYNAME AS "Priority", std.STATUSNAME AS "Request Status",
LONGTODATE(wo.CREATEDTIME) AS "Created Time",
extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "hh",
extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "minu",extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "total minutes"  FROM WorkOrder wo
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN PriorityDefinition pd ON wos.PRIORITYID=pd.PRIORITYID
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE wo.ISPARENT='1'  and
extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP)  > 1158 or extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) < 438

6 AM - 10 PM

SELECT wo.WORKORDERID AS "Request ID", pd.PRIORITYNAME AS "Priority", std.STATUSNAME AS "Request Status",
LONGTODATE(wo.CREATEDTIME) AS "Created Time",
extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "hh",
extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "minu",extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "total minutes"  FROM WorkOrder wo
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN PriorityDefinition pd ON wos.PRIORITYID=pd.PRIORITYID
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE wo.ISPARENT='1'  and
extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP)  > 360
and extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) < 1320

 10 PM - 6 AM

SELECT wo.WORKORDERID AS "Request ID", pd.PRIORITYNAME AS "Priority", std.STATUSNAME AS "Request Status",
LONGTODATE(wo.CREATEDTIME) AS "Created Time",
extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "hh",
extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "minu",extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) "total minutes"  FROM WorkOrder wo
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN PriorityDefinition pd ON wos.PRIORITYID=pd.PRIORITYID
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE wo.ISPARENT='1'  and
extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP)  > 1320
and extract(hour from to_timestamp(wo.createdtime/1000)::TIMESTAMP)*60 +  extract(minute from to_timestamp(wo.createdtime/1000)::TIMESTAMP) < 360

We have to calculate minutes in 24 hour format.

Example:  

For 6 AM:  00:00 - 06:00=> 6 Hours (6*60 minutes)= 360 minutes.

For 10 PM: 00:00 - 22:00=> 22 Hours (22*60 Minutes)= 1320 Minutes​