select * from 表 tem where 日期='2003-08-09' and (select sum(数量) from 表 where 日期='2003-08-09' and 序号<=tem.序号)<=1000

解决方案 »

  1.   

    create table t1(id int,sl int,rq datetime)
    insert t1 select 1    ,       300,        '2003-08-09'
    union all select 2   ,        400 ,       '2003-08-09'
    union all select 3  ,         532  ,      '2003-08-09'
    union all select 4 ,          232   ,     '2003-08-09'
    union all select 5,           341    ,    '2003-08-10'
    alter table t1 add zsl int
    go
    declare @i int 
    set @i = 0
    update t1 set zsl = @i,@i = @i+sl where rq = '2003-08-09'Select id,sl,rq from t1 where id<(Select min(id) from t1 where zsl > 1000)id          sl          rq                                                     
    ----------- ----------- ------------------------------------------------------ 
    1           300         2003-08-09 00:00:00.000
    2           400         2003-08-09 00:00:00.000(所影响的行数为 2 行)-- drop table t1
      

  2.   

    还是大力的简单。
    create table t1(id int,sl int,rq datetime)
    insert t1 select 1    ,       300,        '2003-08-09'
    union all select 2   ,        400 ,       '2003-08-09'
    union all select 3  ,         532  ,      '2003-08-09'
    union all select 4 ,          232   ,     '2003-08-09'
    union all select 5,           341    ,    '2003-08-10'select * from t1 tem where rq='2003-08-09' 
    and (select sum(sl) from t1 where rq='2003-08-09' and id<=tem.id)<=1000
    id          sl          rq                                                     
    ----------- ----------- ------------------------------------------------------ 
    1           300         2003-08-09 00:00:00.000                                2           400         2003-08-09 00:00:00.000                                (所影响的行数为 2 行)