34,571
社区成员
发帖
与我相关
我的任务
分享
--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([id] int,[金额] int)
Insert #T
select 2,30 union all
select 3,30 union all
select 4,30 union all
select 11,9 union all
select 12,1 union all
select 13,1 union all
select 14,15 union all
select 15,33 union all
select 16,5 union all
select 17,8 union all
select 18,14 union all
select 19,3
Go
--测试数据结束
SELECT MIN(id)
FROM ( SELECT b.Id ,
SUM(a.金额) AS 金额
FROM #T a
JOIN #T b ON b.id >= a.id
GROUP BY b.Id
HAVING SUM(a.金额) > 100
) t