title: SQL Query-Group by and filters
body: <p>I have the table  as shown in below image.</p>
  
  <p><img src="https://i.stack.imgur.com/Av7ez.png" alt="enter image description here"></p>
  
  <p>I am trying to get the latest <code>status_id</code>, grouped by <code>team_id</code> and based on max of <code>created_date</code>.</p>
  
  <pre><code> --Latest status for each team based on created date
  SELECT *
  FROM  ProductionHistory
  WHERE created_Date IN (
                        SELECT MAX(created_Date)
                        FROM  ProductionHistory 
                        GROUP BY TeamID
                        )
  </code></pre>
  
  <p>That's fine, here is the result:</p>
  
  <p><img src="https://i.stack.imgur.com/ztsff.png" alt="enter image description here"></p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>How to ignore the <code>assigned_to</code> null then find latest record for team?</li>
  <li>When there is only one record with <code>assigned_to</code> null for team, let's consider that.</li>
  </ol>
  
  <p>For example: for Team_id 5 there is only one record with assigned_to null, we don't have any other record for team_id 5 with assigned_to set some value.
  So we have consider this.</p>
  
  <p>For team id 3 query result should ignore the record 4 (though max date), query result should contain record 2.</p>
  
  <p>Here is the final result I am expecting:</p>
  
  <p><img src="https://i.stack.imgur.com/y46CG.png" alt="enter image description here"></p>