Q:

Select Values While Sum

I have a table with a date and an integer value.  I want to sort the table by the date and pick the top n rows until the integer values sum up to 12 or more. 

A:

You can use a cumulative sum:
select t.*
from (select t.*, sum(val) over (order by date) as sum_val
      from t
     ) t
where sum_val - val < 12
order by date

