C'est ce qu'on appelle le "problème des îles" et j'y ai vu une solution (crédit Itzik Ben Gan)
select tool_number,
min(time) 'in',
max(time) 'out',
count(*)
from (
select tool_number,
time,
ROW_NUMBER() OVER (ORDER BY time) - ROW_NUMBER() OVER (PARTITION BY Tool_Number ORDER BY time) AS Grp
from #temp
) as a
group by grp, tool_number
order by min(time)