If I understand your question correctly, you need to fetch value from two different rows. If that is the case, one way is to use the table twice in the select statement. In other words something like (pseudo code)
select ...
from tablename a,
tablename b
where a.id = b.id
and b.in = (select min(c.in)
from tablename c
where c.id = a.id
and c.in > a.out)
Depending on the database version, you can possibly do the same with
LAG
function. Have a look at
How to fetch data from the previous or next rows in the resultset[
^]