title: Finding closest expiration date
body: <p>I have a table with columns <code>ItemCode</code> , <code>ItemCount</code>, <code>ExpiredDate</code> in which the expired date of items are saved when stocks of items increase. I have a View which shows current stocks of my items and it's columns are <code>ItemCode</code> and <code>ItemStock</code>.</p>
  
  <p><strong>Table</strong></p>
  
  <pre><code>ItemCode, ItemCount, ExpiredDate
  1001    , 200      , 2010/01/01
  1001    , 100      , 2020/02/01
  1001    , 200      , 2021/03/01
  1002    , 150      , 2020/03/01
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>ItemCode, ItemStock
  1001    , 250
  1002    , 40
  1003    , 50
  1004    , 60
  </code></pre>
  
  <p>I want a query that returns closest expired date according to items stock.</p>
  
  <p><strong>Result</strong></p>
  
  <pre><code>ItemCode, ClosestExpirationDate
  1001    , 2020/02/01
  1002    , 2020/03/01
  1003    , -----
  1004    , -----
  </code></pre>