title: Count days within dateranges while excluding overlapping days
body: <p>I'm looking for the number of days within several dateranges. I used the datediff function to sum the days, but now I want to exclude overlapping days. So from the oldest date untill curdate I would like to have the number of days within the dateranges and every day only counted once if it is in an overlapping range.</p>
  
  <p>My table looks like this:</p>
  
  <pre><code>Person_id |      Start_date      | End_date              | Count
   83244       2014-09-01 00:00:00    2014-09-06 00:00:00    5
   83244       2014-09-08 00:00:00    2015-09-07 00:00:00    364
   83244       2015-01-15 00:00:00    2015-02-01 00:00:00    17
  </code></pre>
  
  <p>If I sum this I would get 382, but the answer I'm looking for is 369. Since the last row is completely overlapping the second row.</p>
  
  <p>Does anyone have a solution?</p>