I have a table named Worker Send Times and in there are two fields named start and end (both are timestamp):
if I have all records I want to get the difference in hours from start and end time and the total count how many times he worked so I have to do at first differnce in hours and then calculate all diference in hours with all records. My current query is this:
SELECT
wst.id,
wst.start_time as start,
wst.end_time as end,
l.name,
FROM workers_send_times wst
INNER JOIN workers_plan wp
ON wp.id = wst.workers_plan_id
LEFT JOIN location_orders lo
ON lo.id = wp.location_orders_id
LEFT JOIN location l
ON l.id = lo.location_id
WHERE wst.user_id = $2
AND extract(MONTH FROM start) = $3 AND extract(YEAR FROM end) = $6
ORDER BY wst.id, wst.send_start_at
in the query I only want to show the records from a given month and year. But how can I get the difference in hours and total all counts ?