title: SQL - Select number of record based on SUM conditions
body: <p>if you have a order table, is that possible to select all the records which have sum of amount smaller than $1000, assuming that the table already ordered by amount desc
  Example:</p>
  
  <pre><code>id product_id amount
  1  1          500
  2  3          400
  3  2          300
  4  1          200
  </code></pre>
  
  <p>Get all the orders which have sum of amount smaller than $1000
  then it should return 1 &amp; 2, because the sum of amount of 1 and 2 is 900 &lt; 1000</p>
  
  <p>Get all the orders which have sum of amount smaller than $1300
  then it should return 1,2,3 because the sum of amount of 1,2,3 is 1200 &lt; 1300</p>