Cumulative Query with Laravel Eloquent
Hey guys!
I have a products table with a leftover column representing how many products left over.
Now I want to write a query to find all remained products until a certain point.
id | store_name | product_id | leftover
-- | -------------------- | --------------- | -----------
1 | Store 1 | 1 | 10
2 | Store 2 | 1 | 20
3 | Store 3 | 1 | 25
Let's say we want to sell 15 products. Our query should return just rows with ids 1 and 2 because of it satisfies our need.
We need to sum leftovers until a certain point (here is 15). So we should have a calculation per row. I find some solution using MySQL variables but there is a problem that it's not supported in SQLite for test purposes.
Please or to participate in this conversation.