Detta kallas "öproblemet" och jag har sett detta som en lösning (kreditering 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)