34,594
社区成员
发帖
与我相关
我的任务
分享
use test
go
if object_id('test.dbo.tb') is not null drop table tb
-- 创建数据表
create table tb
(
id int,
point int
)
go
--插入测试数据
insert into tb select 1,5
union all select 2,6
union all select 3,7
union all select 4,8
union all select 5,10
go
--代码实现
select * from (
select *,num=(select sum(point) from tb where id<=t.id) from tb t
)t where num=18
/*测试结果
id point num
---------------------
3 7 18
(1 行受影响)
*/