select count(*) from sessions where start_time < $end_of_segment and (stop_time > $start_of_segment || stop_time IS NULL);