表中是每天一条记录吧!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
select a.fdatetime,a.index-isnull(b.index,0) from #temp a left join #temp b on a.id=b.id-1
from 表 as A, 表 as B
where A.FDateTime = @edatetime
and cast(A.FDateTime as datetime)
= dateadd(dd, 1, cast(B.FDateTime as datetime))
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
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
from 表 as A, 表 as B
where A.FDateTime = @edatetime
and cast(A.FDateTime as datetime)
= dateadd(dd, 1, cast(B.FDateTime as datetime))
上面这段说index附近有语法错误,表我已经替换成表名
象这样的表,要得到昨天的记录怎么写查询?我现在是getdate()-1-cast(FDateTime as datetime) <1 and getdate()-1-cast(FDateTime as datetime)>0 来得到,总觉得怪怪,有没有好点的写法?