title: Get as much as possible rows until a given minimum amount is achieved in MySQL
body: <p>For example we have the following Query:</p>
  
  <pre><code>SELECT
      item_id,
      order_id,
      product_id,
      qty
  FROM
      orders
  WHERE
      product_id = 18253
  ORDER BY 
      item_id ASC;
  </code></pre>
  
  <p>... and that's the result of it:</p>
  
  <pre><code>+---------+----------+------------+------+
  | item_id | order_id | product_id | qty  |
  +---------+----------+------------+------+
  |   15329 |     7369 |      18253 |    3 |
  |   15330 |     7370 |      18253 |    1 |
  |   15331 |     7371 |      18253 |    7 |
  |   15332 |     7372 |      18253 |    1 |
  |   15333 |     7373 |      18253 |    1 |
  |   15334 |     7377 |      18253 |    1 |
  |   15336 |     7379 |      18253 |    2 |
  |   15337 |     7380 |      18253 |    1 |
  |   15340 |     7383 |      18253 |    1 |
  |   15341 |     7384 |      18253 |    1 |
  +---------+----------+------------+------+
  10 rows in set (0,04 sec)
  </code></pre>
  
  <p>Now I want to get all possible rows (as much as possible) until the sum of <code>qty</code> is at least five. Five should be the minimum quantity. Sorted by ascending (item_id).</p>
  
  <pre><code>+---------+----------+------------+------+
  | item_id | order_id | product_id | qty  |
  +---------+----------+------------+------+
  |   15329 |     7369 |      18253 |    3 |  // 3
  |   15330 |     7370 |      18253 |    1 |  // 4
  |   15331 |     7371 |      18253 |    7 |  // 11
  +---------+----------+------------+------+
  </code></pre>
  
  <p>So the sum of <code>qty</code> above is 3, 4, 11. The third row makes the sum 5 or above so that's all I need.</p>
  
  <p>Another example when I have a quantity of 13 in my inventory:</p>
  
  <pre><code>+---------+----------+------------+------+
  | item_id | order_id | product_id | qty  |
  +---------+----------+------------+------+
  |   15329 |     7369 |      18253 |    3 | // 3
  |   15330 |     7370 |      18253 |    1 | // 4
  |   15331 |     7371 |      18253 |    7 | // 11
  |   15332 |     7372 |      18253 |    1 | // 12
  |   15333 |     7373 |      18253 |    1 | // 13
  +---------+----------+------------+------+
  </code></pre>
  
  <p>How can I do that, is there a possibility?</p>
  
  <p>thanks :)</p>