I have an issue where I'm selecting from two tables as follows:
select SUM(tc.WEEKLY_HOURS),
SUM(pc.var_cash)
from time_capture tc
LEFT OUTER JOIN PAYMENT_CAPTURE pc on tc.EMP_NO = pc.emp_no
AND tc.EFFECTIVE_DATE = pc.EFFECTIVE_DATE
where tc.effective_date = '17 June, 2012'
GROUP BY LEFT(tc.COST_CENTRE, 4)
The two tables contain:
time_capture
emp_no EFFECTIVE_DATE weekly_hours
---------- ----------------------- ----------------------
1234 2012-06-17 28
PAYMENT_CAPTURE
emp_no EFFECTIVE_DATE INPUT_CODE cost_centre var_cash
---------- ----------------------- ---------- ------------------------- ----------------------
1234 2012-06-17 KEY 5607.03 45
1234 2012-06-17 OTHER 5607.03 19.23
I was expecting the sum(weekly_hours)
to return 28 but it returns 56 (below) due (I think) the two rows in payment_capture
.
Could some point me in the right direction on this?
Many thanks.
weekly_hours var_cash
---------------------- ----------------------
56 64.23