I have table T1 and T2.
T1
ID TIME1 TIME2
1001 1 10
1002 1 20
T2
ID STATUS TIME
1001 NEW 1
1001 CLOSED 10
1002 NEW 1
1002 HOLD 5
1002 CLOSED 13
I want result TIME2-TIME1 if status HOLD does not exist in table T2; or TIME2-TIME1-TIME if status HOLD exist in table for that record
1001 9 (10-1)
1002 14(20-1-5)
I initially wrote SQL query but this does not work because it returns NULL for first record while the for the second record result is OK
SELECT T1.ID,T1.TIME2-T1.TIME1-T2.TIME
FROM T1
LEFT OUTER JOIN T2 ON T1.ID=T2.ID AND T2.STATUS='HOLD'
Thanks
or in short