Running total until specific condition is met
As suggested in comments, I can get the latest id of the order in a single position by watching running total goes to zero. Then I can just select orders in range 

declare @latestId int;
WITH T1
     AS (SELECT *,
                SUM(qty) OVER (ORDER BY id ROWS UNBOUNDED PRECEDING) AS total
         FROM   [dbo].[orders])
SELECT top (1) @latestId = id
FROM   T1
WHERE  total &lt;= 0
order by id

select * from [dbo].[orders] where 1 &lt;= id and id &lt;= @latestId