求助 请高手们帮我看看这个程序 在线等 谢谢
本帖最后由 binbin140113 于 2009-2-2 16:37 编辑declare @a datetime
select @a = "Feb 1 2009 12:00AM"
select sum(datediff(mi, runstate_time, @a)) "时间",signal_id,runstate_value,device_id
from runstate_200901_101
where signal_id=66199 AND runstate_value = 0 AND device_id = 6643714
结果
时间 signal_id runstate_value device_id
----------- ----------- -------------- -----------
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 66199 0 6643714
3357847 527 1 6643714
3357847 66199 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 66199 0 6643714
3357847 527 1 6643714
3357847 66199 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
3357847 66199 0 6643714
3357847 527 1 6643714
3357847 66199 1 6643714
3357847 527 0 6643714
3357847 527 1 6643714
3357847 527 0 6643714
问题是where 语句中的条件设定失效了只有device_id 这个条件没有失效 请高手们给解答一下原因 谢谢 DBCC一下库跟表试试。 sum(datediff(mi, runstate_time, @a)) 我很不明白为什么前面要用SUM,你是想把这个表所有的时间都加起来吗。如果是这样何不
select (datediff(mi, runstate_time, @a)) "时间",signal_id,runstate_value,device_id
from runstate_200901_101
where signal_id=66199 AND runstate_value = 0 AND device_id = 6643714 compute sum("时间") 额 看不懂 帮不了你 declare @a datetime
select @a = "Feb 1 2009 12:00AM"
select sum(datediff(mi, runstate_time, @a)) "时间",signal_id,runstate_value,device_id
from runstate_200901_101
where signal_id=66199 AND runstate_value = 0 AND device_id = 6643714
group by signal_id,runstate_value,device_id
但我也不明白sum(datediff(mi, runstate_time, @a)) 是什么意思?
页:
[1]