Hi @Davis ,
Welcome to Microsoft Q&A!
For this type of problem we recommend that you post CREATE TABLE statements for your tables together with INSERT statements with sample data, enough to illustrate all angles of the problem. We also need to see the expected result of the sample.
If we have 12 rows , and the total of first 10 rows is 100 or bigger than 100, need we still return current row?
If no, please refer below example and check whether it is helpful to you.
create table yourtable
(id int,
duration int)
insert into yourtable values
(1,11),
(2,8),
(3,9),
(4,12),
(5,14),
(6,9),
(7,13),
(8,10),
(9,12),
(10,8),
(11,10),
(12,12),
(13,11)
select * from yourtable
where id >(select min(id) from (select id,SUM(duration) OVER (ORDER BY ID ROWS UNBOUNDED PRECEDING) total from yourtable) a where total>=100)
Output:
id duration
11 10
12 12
13 11
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.