title: How can I subtract two row's values within same column with getting latest record of date using sql query?
body: <p>I want to display the subtraction of the latest record in stage 2 and the latest record in stage 3
  This is the table structure:</p>
  
  <pre><code>   ------------------------------------
        name |stage| date
     ------------------------------------
      | ABC  | 2   | 2016-5-07
      | ABC  | 2   | 2016-6-08  
      | ABC  | 3   | 2016-6-07
      | ABC  | 3   | 2016-12-08 
      | PQR  | 2   | 2016-6-07
      | PQR  | 2   | 2016-8-12  
      | PQR  | 3   | 2016-9-07
      | PQR  | 3   | 2016-10-08 
  </code></pre>
  
  <p>I want to subtract date 2016-6-08 from date  2016-12-08 where name is ABC, they will be 183 days
  And subtract 2016-8-12 from 2016-10-08 where name is PQR</p>
  
  <p>Output should be like as</p>
  
  <pre><code>| name | Date |
   ---------------
  | ABC  | 183  |
  | PQR  | 61   |
  </code></pre>