当前位置: 代码迷 >> Sql Server >> 怎么计算前10小时的数据平均值
  详细解决方案

怎么计算前10小时的数据平均值

热度:13   发布时间:2016-04-27 13:31:12.0
如何计算前10小时的数据平均值
如题。有一个时间,和数值举例如下

createtime num  
2012-04-07 1:01 1  
2012-04-07 1:12 20
2012-04-07 3:01 100  
2012-04-07 4:12 201
.........................................

怎么求Num前10小时数据的平均值。谢谢,在线等。

 

------解决方案--------------------
SQL code
select avg(num) from tablea where createtime>='2012-04-07 00:00'createtime<='2012-04-07 10:00'
------解决方案--------------------
SQL code
select avg(num) from tablea where createtime>=DATEADD(hh,-10,GetDate()) and createtime<= GetDate()
  相关解决方案