表中是每天一条记录吧!select identity(int,1,1) as id,* into #temp from table
select a.fdatetime,a.index-isnull(b.index,0) from #temp a left join #temp b on a.id=b.id-1

解决方案 »

  1.   

    select A.FDateTime, cast(A.index as integer) - cast(B.index as integer)
     from 表 as A, 表 as B
     where A.FDateTime = @edatetime
       and cast(A.FDateTime as datetime) 
         = dateadd(dd, 1, cast(B.FDateTime as datetime))
      

  2.   

    select A.FDateTime, cast(A.index as integer) - cast(B.index as integer)
     from 表 as A left join 表 as B 
      on cast(A.FDateTime as datetime) 
         = dateadd(dd, 1, cast(B.FDateTime as datetime))
     order by A.FDateTime desc
      

  3.   


    create table #p(FDateTime char(10),indexa  int)insert #p values('2003-03-26',6)
    insert #p values('2003-03-25',20)
    select a.indexa-(select indexa from #p where datediff(day,cast(fdatetime as datetime),getdate())=1) as 结果
    from #p a 
    where a.Fdatetime=convert(char(10),getdate(),120)--
    -16
      

  4.   

    select A.FDateTime, cast(A.index as integer) - cast(B.index as integer)
     from 表 as A, 表 as B
     where A.FDateTime = @edatetime
       and cast(A.FDateTime as datetime) 
         = dateadd(dd, 1, cast(B.FDateTime as datetime))
    上面这段说index附近有语法错误,表我已经替换成表名
      

  5.   

    字段是pindex,是我搞错了。但是我想得到的就是今天和昨天的差值、日期为今天的
      

  6.   

    我测试了以上的语句,都不对。最后我自己建立了2个视图,分别得到今天和昨天的记录,然后用第三个视图来得到pindex字段的查值。
    象这样的表,要得到昨天的记录怎么写查询?我现在是getdate()-1-cast(FDateTime as datetime) <1 and getdate()-1-cast(FDateTime as datetime)>0 来得到,总觉得怪怪,有没有好点的写法?