取到“和”小于500的明细
做一个测试表
create table #t
(
isid int primary key identity(1,1),
amount decimal(18,2)
)
go
insert into #t values(23.43)
insert into #t values(213.43)
insert into #t values(523.3)
insert into #t values(23.4)
insert into #t values(263.23)
insert into #t values(223.43)
insert into #t values(223.43)
insert into #t values(293.43)
insert into #t values(223.3)
insert into #t values(23.16)
drop table #t
请问 大家如何才能按照isid顺序由小到大 取到“和”小于 500的明细。此表结果就是取到前两条
就是按照顺序来取到连续数据和小于500的明细
分少 请各位帮帮忙
[解决办法]
select * from #t as a where exists(select 1 from #t where isid<=a.isid having sum(amount)<500)