我正在做一个关于水传感器测量的图表。进行3次测量并存储在表格#34;传感器"每一分钟。
就我的目的而言,我每隔2分钟需要一次数据。也就是说,我将获得5个读数(总共15行),记录10分钟的数据。
以下是示例:
RecordDate Depth
-----------------------------------
2016-01-01 07:01:00 112
2016-01-01 07:01:00 116
2016-01-01 07:01:00 108
2016-01-01 07:00:00 106
2016-01-01 07:00:00 102
2016-01-01 07:00:00 103
2016-01-01 06:59:00 111
2016-01-01 06:59:00 110
2016-01-01 06:59:00 109
2016-01-01 06:58:00 108
2016-01-01 06:58:00 107
2016-01-01 06:58:00 106
2016-01-01 06:57:00 109
2016-01-01 06:57:00 104
2016-01-01 06:57:00 105
2016-01-01 06:56:00 112
2016-01-01 06:56:00 114
2016-01-01 06:56:00 115
2016-01-01 06:55:00 102
2016-01-01 06:55:00 104
2016-01-01 06:55:00 105
2016-01-01 06:54:00 108
2016-01-01 06:54:00 109
2016-01-01 06:54:00 112
2016-01-01 06:53:00 113
2016-01-01 06:53:00 115
2016-01-01 06:53:00 117
2016-01-01 06:52:00 105
2016-01-01 06:52:00 109
2016-01-01 06:52:00 112
预期记录结果:
2016-01-01 07:01:00 112
2016-01-01 07:01:00 116
2016-01-01 07:01:00 108
2016-01-01 06:59:00 111
2016-01-01 06:59:00 110
2016-01-01 06:59:00 109
2016-01-01 06:57:00 109
2016-01-01 06:57:00 104
2016-01-01 06:57:00 105
2016-01-01 06:55:00 102
2016-01-01 06:55:00 104
2016-01-01 06:55:00 105
2016-01-01 06:53:00 113
2016-01-01 06:53:00 115
2016-01-01 06:53:00 117
我的SQL查询获得10分钟记录:
Declare @LastTime datetime
select top 1 @LastTime = RecordDate
from Sensor
order by RecordDate desc
select *
from Sensor
where datediff(n, RecordDate, @LastTime) > 10
那么如何使用SQL每2分钟获取一次数据呢?
或者如果不容易,可以在VB.net中过滤数据集。
答案 0 :(得分:1)
如果您希望每隔x时间在.net应用程序中使用数据,那么您应该使用Timer
来帮助您在x时间内获取数据,例如来自MSDN的代码
private static System.Timers.Timer aTimer;
public static void Main()
{
SetTimer();
Console.WriteLine("\nPress the Enter key to exit the application...\n");
Console.WriteLine("The application started at {0:HH:mm:ss.fff}", DateTime.Now);
Console.ReadLine();
aTimer.Stop();
aTimer.Dispose();
Console.WriteLine("Terminating the application...");
}
private static void SetTimer()
{
// Create a timer with a two second interval.
aTimer = new System.Timers.Timer(2000);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
aTimer.Enabled = true;
}
private static void OnTimedEvent(Object source, ElapsedEventArgs e)
{
Console.WriteLine("The Elapsed event was raised at {0:HH:mm:ss.fff}",
e.SignalTime);
}
代码在C#中,但您可以转换为Vb.net,