如题。有一个时间,和数值举例如下
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()