select sum(value) as LostValue from ElectroBalance where addr = 257 and getTime>=38563.0 and getTime<=38594.0select sum(value) as LostValue from ElectroBalance where addr = 257 and getTime>=0 and getTime<= 100000getTime为datetime数据类型,前一条语句结果为138,后一条为114,也就是说前一条结果比后一条大,请问为什么?
注:114为正确的答案,因为:
select sum(value) as LostValue from ElectroBalance where addr = 257select sum(value) as LostValue from ElectroBalance where addr = 257 and datediff(d,GetTime ,cast(38563.0 as datetime))<=0 and datediff(d,getTime,cast(38594.0 as datetime))>=0两条语句结果都是114。更奇怪的是,在38563.0和38564.0上都加2,即如下:
select sum(value) as LostValue from ElectroBalance where addr = 257 and getTime>=38565.0 and getTime<= 38596.0
结果也是114!!!

解决方案 »

  1.   

    getTime为datetime数据类型,前一条语句结果为138,后一条为114,也就是说前一条结果比后一条大,请问为什么?
    ----------------------------------------------------------------
    从你的结果上看,38594.0-38596.0的时间段存在value为负值的数据
    所以在getTime>=38563.0 and getTime<=38594.0范围里的值为138
    超出这个范围的时候,负值的数据也被计算进去了,也就变成114了
    你可以查看一下你的数据库,查一下是否真的存在value为负值的数据,该数据的时间段是什么