title: How to write Oracle query to find a total length of possible overlapping from-to dates
body: <p>I'm struggling to find the query for the following task</p>
  
  <p>I have the following data and want to find the total network day for each unique ID</p>
  
  <pre><code>ID  From        To          NetworkDay
  1   03-Sep-12   07-Sep-12   5
  1   03-Sep-12   04-Sep-12   2
  1   05-Sep-12   06-Sep-12   2
  1   06-Sep-12   12-Sep-12   5
  1   31-Aug-12   04-Sep-12   3
  2   04-Sep-12   06-Sep-12   3
  2   11-Sep-12   13-Sep-12   3
  2   05-Sep-12   08-Sep-12   3
  </code></pre>
  
  <p>Problem is the date range can be overlapping and I can't come up with SQL that will give me the following results</p>
  
  <pre><code>ID  From        To          NetworkDay
  1   31-Aug-12   12-Sep-12   9
  2   04-Sep-12   08-Sep-12   4
  2   11-Sep-12   13-Sep-12   3
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>ID  Total Network Day
  1   9
  2   7
  </code></pre>
  
  <p>In case the network day calculation is not possible just get to the second table would be sufficient.</p>
  
  <p>Hope my question is clear</p>