I was wondering if I could get any help with the following problem.
I have a table of transactions (simplified below) and I only want to select transactions until my amount total reaches a certain amount.
Transactions
table
id | date | amount
----|----------|--------
1 | 1/1/2012 | 2
2 | 2/1/2012 | 3
3 | 3/1/2012 | 4
4 | 4/1/2012 | 20
5 | 5/1/2012 | 1
6 | 6/1/2012 | 2
Now say I want to do a select on the table until the amount total is 6 i.e just the first 2 rows, how would I do this?
I was thinking of maybe doing a join with itself and some sum but not really getting anywhere. I'd prefer no to use any functions if possible.
Also anything similar for minimum amount.
Any help would be much appreciated :)
T
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…