title: C# SQL Subtract Product Quantity at FIFO
body: <p>I just wondering how to subtract quantity of the same product with different date expiration.</p>
  
  <p>Example</p>
  
  <p>Table <strong>Inventory</strong>:</p>
  
  <pre><code>Product | Qty | Expiration |
  --------+-----+------------+
  Oreo    | 2   | 10/18/2017 |
  Oreo    | 6   | 10/09/2017 |
  </code></pre>
  
  <p>I have request to table <code>Inventory</code> of <code>Oreo</code> with qty of 7. That 7 Oreo request
  must be subtracted to first to expire which is 10/09/2017. My request has remaining of 1 Oreo will be subtracted to next expiration which is 10/18/2017 so the table will be like this</p>
  
  <pre><code>Product | Qty | Expiration |
  --------+-----+------------+
  Oreo    | 1   | 10/18/2017 |
  Oreo    | 0   | 10/09/2017 |
  </code></pre>