Deal Stages - Need consistent results


I need to get the time spent per stage for all deals. I would most likely loop through each deal ID, however, each deal goes through different stages and the results vary per deal. Is there a way to loop through the deals without knowing the exact stages beforehand?