I want to query data within a period of time according to the interval
Select * from monitoring temperature table where monitoring temperature table. Time Between '"+ STR (dtstart. Value) +"' and '"+ STR (dtend. Value) +" 'order by ID
This is a query within a period of time. Now we need to add a time interval for the query. zhuyun, hope you can answer this question.
The dtstart. Value and dtend. value are dtpicker1 controls.
Example: for example, I thought there was a piece of data between 19:03:31 and 10:38:21, but I didn't want it to be retrieved in a few seconds, I need a data record in 5 minutes or at any time. For example, if I have a record at 19:03:31, the next record is recorded at 19:08:31 (if there is no such record, it is closest to getting a record before and after the record ), A lot of data is not displayed at 19:03:31. Thank you!
Try
Select * from monitoring temperature table A where time between' "+ STR (dtstart. value) + "'and'" + STR (dtend. value) + "'and not exists (select time from monitoring temperature table where datediff (MI, time,. time) <= 5) order by ID
I think the interval can be changed.
For example, add a text
Text1.text = Interval
Thank you for choosing upstairs.
Add text1.text and click Next,
Select * from monitoring temperature table A where time between' "+ STR (dtstart. value) + "'and'" + STR (dtend. value) + "'and not exists (select time from monitoring temperature table where datediff (MI, time,. time) <= "+ STR (text1.text) +") order by ID
A is a different table name.
"Text1.text = interval": What is the content that you specify in text1.text? When you use the sentence, text1.text can only contain the number of partitions separated by partitions, for example, 5.
Yes. If you have a fixed interval
So far
Select * from monitoring temperature table where monitoring temperature table. time between' "+ STR (dtstart. value) + "'and'" + STR (dtend. value) + "'and datediff (MI,'" + STR (dtstart. value) + "', time) %" + STR (text1.text) + "= 0 order by ID
It is easier to clarify the principle of the operation:
1. merge a calculation column, which is to make a datediff between the "monitoring temperature table. Time" and a benchmark time to calculate the gap between them, for example, retrieve the gap by minute.
2. Use the result set in step 1 as the table, and then place an SQL statement to filter the table. For example, if the SQL statement is used once every five minutes, the where statement is used to calculate the column % 5 = 0.
This will be very easy to implement.
Follow the above steps to practice:
The first step can also be completed directly in the WHERE clause in specific implementation. You can do this:
"Select * from monitoring temperature table where monitoring temperature table. time between' "+ STR (dtstart. value) + "'and'" + STR (dtend. value) + "'and datediff (" + "mi" + ",'" + STR (dtstart. value) + "', time) %" + "5" + "= 0 order by ID"
Note that I added the time interval judgment in the above conditions. Note that the 1st PARAMETERS OF THE datediff function use Mi (the two sides cannot contain single quotes ), this represents the interval by minute, And the last 5, which represents the interval of five units (Modulo 5 = 0). In combination, it becomes counted from the start time, every five minutes.