title: how to count days between two dates with where conditions
body: <p>i have table and it has following data:</p>
  
  <pre><code>USERID  NAME  DATEFROM      DATETO
  1       xxx  2014-05-10     2014-05-15 
  1       xxx  2014-05-20     2014-05-25   
  4       yyy  2014-04-20     2014-04-21
  </code></pre>
  
  <p>now i have sql query like :</p>
  
  <pre><code>select * from leave where datefrom&gt;='2014-05-01' and dateto&lt;='2014-05-31'
  </code></pre>
  
  <p>so now i want output :</p>
  
  <pre><code>userid name total_leave_days
  1      xxx   12
  4      yyy   2
  
  (2014-05-10 - 2014-05-15 )=6 days
  (2014-05-20 - 2014-05-25 )=6 days
  total = 12 days for useid 1
  (2014-04-20 - 2014-04-21)= 2 days for userid 4
  </code></pre>
  
  <p>how can i calculate this total days .?</p>