从数据库特定的时间间隔获取值间隔、数据库、时间

2023-09-05 23:57:11 作者:小时候,快乐是件简单的事

我想从数据库在C#中特定的时间间隔获取价值观和需要一个单一的查询。 这是我的数据库看起来像

I want to fetch values from database with specific intervals in C# and need a single query for that. This is how my Database looks like


Id   SensorId    Value        CreatedOn   
------------------------------------------------      
1       8        33.5      15-11-2012  5:48 PM        
2       5        49.2      15-11-2012  5:48 PM
3       8        33.2      15-11-2012  5:49 PM  
4       5        48.5      15-11-2012  5:49 PM  
5       8        31.8      15-11-2012  5:50 PM 
6       5        42.5      15-11-2012  5:50 PM 
7       8        36.5      15-11-2012  5:51 PM 
8       5        46.5      15-11-2012  5:51 PM 
9       8        39.2      15-11-2012  5:52 PM 
10      5        44.4      15-11-2012  5:52 PM 
11      8        36.5      15-11-2012  5:53 PM 
12      5        46.5      15-11-2012  5:53 PM 
13      8        39.2      15-11-2012  5:54 PM 
14      5        44.4      15-11-2012  5:54 PM 
..      ..       .....     ...................

的时间间隔是在分钟。 所以,如果时间间隔为10分钟,那么我们所需要的值在5:48,5:58,6:08等等......

The interval is in minutes. So, if the interval is 10 minutes, then we need the values at 5:48, 5:58, 6:08 and so on...

我试着用whil​​e循环这样做,但它采取了大量的时间,因为我拍摄多数据库查询。

I tried doing it with a while loop but it is taking a lot of time as i shoot multiple queries to the database.

有没有办法获得的数据在一个单一的查询?

Is there any way of getting the data in a single query?

推荐答案

您可以使用的日期部分 >