title: Finding a difference in time in minutes for values in the same column
body: <p>What I want to do here is to find the time difference between <code>StatusID = 'Processed'</code> and <code>StatusID = 'NEW'</code> according to its owner ID. and after getting the difference for each owner ID, I want to find the maximum, minimum and average time difference. This is the sample data for it.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>OWNER_ID</th>
  <th>CREATED_TIME</th>
  <th>STATUS_ID</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>2020-07-16 08:29:29.000</td>
  <td>NEW</td>
  </tr>
  <tr>
  <td>1</td>
  <td>2022-02-21 04:38:01.000</td>
  <td>PROCESSED</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2022-02-28 14:24:28.000</td>
  <td>1</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2022-02-28 14:27:32.000</td>
  <td>CONVERTED</td>
  </tr>
  <tr>
  <td>4</td>
  <td>2022-02-28 14:33:06.000</td>
  <td>NEW</td>
  </tr>
  <tr>
  <td>4</td>
  <td>2022-02-28 14:33:19.000</td>
  <td>IN_PROCESS</td>
  </tr>
  <tr>
  <td>5</td>
  <td>2022-03-01 12:01:48.000</td>
  <td>NEW</td>
  </tr>
  <tr>
  <td>5</td>
  <td>2022-03-01 12:02:00.000</td>
  <td>IN_PROCESS</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I have tried out this code to get the time difference but my code is not working.</p>
  <pre><code>SELECT 
      OWNER_ID, 
      DATEDIFF(SECOND, (SELECT CREATED_TIME
                        FROM table
                        WHERE STATUS_ID = 'IN_PROCESS'),
                       (SELECT CREATED_TIME
                        FROM table
                        WHERE STATUS_ID = 'NEW'))
  FROM 
      table
  GROUP BY 
      OWNER_ID
  </code></pre>
  <p>The desired output is in this format and after getting the result, I want to find the maximum, minimum and average time difference.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>OWNER_ID</th>
  <th>TIME_DIFFERENCE(in mins)</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>500</td>
  </tr>
  <tr>
  <td>3</td>
  <td>800</td>
  </tr>
  <tr>
  <td>4</td>
  <td>1300</td>
  </tr>
  </tbody>
  </table>
  </div>