2009-05-17 60 views
1

我試圖從存儲在MySQL中的數據集計算24小時rms(均方根)。我需要獲取特定行偏移量之前24小時內發生的最後24小時的點數。舉例來說,如果我想計算24小時有效值的行號1250,它的時間戳是2007年6月7日午夜,我需要得到它在2007年6月6日和午夜之間發生的所有點。如何從行中選擇最後24小時的行偏移

回答

3

關閉我的頭頂......(MYSQL)

declare @endTime datetime; 
select @endTime=timestamp from data where [email protected] 
select 
    * 
from 
    data 
where 
    timestamp<[email protected] and timestamp>ADDDATE(@endTime,INTERVAL -1 DAY) 

(T-SQL)

declare @endTime datetime2; 
select @endTime=timestamp from data where [email protected] 
select * from data where timestamp<[email protected] and timestamp>dateadd(d,-1,@endTime) 

您可能需要調整日期時間類型來匹配您的數據。

2

您可以直接使用聚合函數對一些設置:

select 
    sqrt(sum(pow(my_value,2))/count(*)) 
from 
    my_table 
where 
    my_date between '2007-06-06 00:00:00' and '2007-06-07 00:00:00'