So I'm kind of stumped here, I have a table setup like this
+-----------+------+
| Timestamp | Size |
+-----------+------+
| 1-1-13 + 10.3 +
+-----------+------+
| 1-3-13 + 6.7 +
+-----------+------+
| 1-5-13 + 3.0 +
+-----------+------+
| 1-9-13 + 11.4 +
+-----------+------+
And I'm wondering if there's any way to run a query like this
SELECT * FROM table ORDER BY timestamp ASC LIMIT BY (SUM(size) <= 20.0);
This should grab the first three rows, because the sum of the size in of the first 3 rows is 20. However, it might not always be 3 rows that equal 20. Sometimes the first row might have a value of 20, and in that case, it should only grab the first one.
I'm already aware that this it's possible to quickly calculate the sum in PHP after the query is run, but I'm trying to accomplish this with just MySQL.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…