I'm hoping someone may be able to help me with what should be a fairly straight forward query but has me stumped.
I have written the below query
SELECT a.post_id,
a.date_from,
a.date_to,
b.description,
b.parttime_pct AS budget_hours,
Sum(a.parttime_pct) AS contract_hours,
b.parttime_pct - Sum(a.parttime_pct) AS remainder
FROM aprresourcepost a
LEFT OUTER JOIN aprpost b
ON(( a.client = b.client
AND a.post_id = b.post_id ))
INNER JOIN ahsresources c
ON(( c.client = a.client
AND c.resource_id = a.resource_id ))
LEFT OUTER JOIN agladdress d
ON(( 'C0' = d.attribute_id
AND c.client = d.client
AND c.resource_id = d.dim_value
AND d.address_type = '1' ))
LEFT OUTER JOIN agldimvalue e
ON(( e.client = b.client
AND e.dim_value = b.dim_value ))
WHERE a.client = 'CI'
AND a.post_id = '14013'
GROUP BY a.post_id,
b.description,
b.parttime_pct,
a.parttime_pct,
a.date_from,
a.date_to
Which returns the below
post_id date_from date_to descr budget_hours contract_hours remainder
14013 2014-10-01 2099-12-31 Reg 140.00 105.00 35.00
14013 2014-12-20 2099-12-31 Reg 140.00 140.00 105.00
What I would like this to show (if possible) is
post_id date_from date_to descr budget_hours contract_hours remainder
14013 2014-10-01 2099-12-31 Reg 140.00 105.00 35.00
14013 2014-12-20 2099-12-31 Reg 140.00 140.00 0.00
This basically indicates that as of any date before the 20th December there is 35 hours remaining on the recommended number of hours (employees) for this role, however as of the 20th December this position is 100% filled, however as I want to include date from and date to the data is summed based on position and date from and date to, I guess I kinda need a rolling total
I know if I remove the date from the select and group by it will show the 140.00 140.00 however I need a way to separate out the dates.
Any help is greatly appreciated.
Thanks guys