Retrieve date ranges from multiple rows
Plan A:  Change the schema to have two date columns.  Then have the code INSERT a row when the item is &quot;assigned&quot; and UPDATE the other column when it is &quot;unasigned&quot;.  This essentially eliminates the entire problem.  And it cuts in half the number of rows needed.
Plan B:  Split the effort.  Using the schema you currently have, SELECT ... ORDER BY ... to get the pairs of rows adjacent.  Then have the application code finish the task by remembering the contents of the first row of each pair (&quot;assigned&quot;) just long enough to blend it with the next row (&quot;unassigned&quot;).