我在ACCESS中有这样一个表:期号  类型  收入我现在要实现这样一种功能:我需要得到类型属于"预支"的下一期的数据,我现在只会得到属于"预支"的期号。strsql := 'select 期号 from 数据表 where 类型="预支";如果没有这样的语句,莫非我要用下面的办法实现?1、strsql := 'select 期号 from 数据表 where 类型="预支";2、在取得属于"预支"的所有期数后,低效率地利用循环从数据库中取出 期号+1 的数据

解决方案 »

  1.   

    select next.期号 from 数据表 as next,数据表 as current
    where current.类型="预支" and (Current.期号+1) = Next.期号
    (基本上没用过Access,试试看行不)
      

  2.   

    select top 1 *
    from table1
    where 类型='预支' and 期号 not in
    (select top 1 期号 from table1 where 类型='预支' )
    order by 类型 
      

  3.   

    select top 1 * from # a
    where 类型='预支'
    and exists(select 1 from # where 类型=a.类型 and id<a.id)--id 为种子数
      

  4.   


    create table #
    (期号 varchar(5),  类型 varchar(10),  收入 tinyint)
    insert into #
    select '001',           '暂欠',           100 union all
    select '002',           '预支',           111 union all
    select '003',           '扣除',           122 union all
    select '004',           '扣除',           133 union all
    select '005',           '预支',           144 union all
    select '006',           '暂欠',           155 union all
    select '007',           '暂欠',           166 union all
    select '008',           '预支',           177 union all
    select '009',           '暂欠',           188 
    select a.* from # a,(select * from # where 类型='预支')b
    where a.期号=b.期号+1/*
    期号    类型         收入   
    ----- ---------- ---- 
    003   扣除         122
    006   暂欠         155
    009   暂欠         188(所影响的行数为 3 行)
    */
      

  5.   

    请问鶴嘯九天,b是不是代我的“数据表”,意思是不是创建一个临时表a来进行处理?
    我的“数据表”数据量较大啊是不是要将“数据表”复制到表a中?
    谢谢了,我是菜鸟。