I want to write a query which returns all rows until the sum of one of the columns value reaches a certain value.
For example in the table below:
If you are using SQL Server, then use CROSS APPLY.