如何从MS Access数据库中检索最新数据 [英] How to retrieve latest data from MS Access database
问题描述
您可以告诉我如何在发送查询时获取数据库中记录的最新数据。就像我有MS Access数据库,我在其中记录了数据以及时间戳,所以当我发送查询时,我应该只获得存储在其中的最新信息,或者根据最后记录的时间从中获取最新数据。 />
以下是我的数据库数据:
DeviceName Window DateTime
Device1 win1 6/10/2013 9:40:57
Device1 win2 6/10/2013 9:40:57
Device1 win1 6/11/2013 9:39:39
Device1 win2 6/11/2013 9:39:39
Device1 win1 6/11/2013 10:39:39
Device1 win2 6/11/2013 10:39:39
Device1 win3 6/11/2013 10:39:40
Device1 win4 6/11/2013 10:39:40
Device1 win5 6/11/2013 10:39:40
正如您所见,设备1被记录为@不同的间隔&在不同的日子里,但是根据这些记录的数据,我只需要最新记录的数据,即记录在@ 10:39:39至10:39:40的表中较低的4个值。在2013年6月11日。如何为此案例编写查询?
您可以尝试使用Top和Order by子句查询表以获取最新的4条记录。类似这样的事情
SELECT TOP 5 [DeviceName],[WindowName],[LogTime]
FROM 设备 ORDER BY [LogTime] DESC
Hi can anybody tell me how to get the latest data logged in database while sending the query. Like i have MS Access database in which i have logged data along with time-stamping, so when i send a query i should get only the latest information stored in it or get the latest data from it based on the last recorded time.
The following is my database data:
DeviceName Window DateTime
Device1 win1 6/10/2013 9:40:57
Device1 win2 6/10/2013 9:40:57
Device1 win1 6/11/2013 9:39:39
Device1 win2 6/11/2013 9:39:39
Device1 win1 6/11/2013 10:39:39
Device1 win2 6/11/2013 10:39:39
Device1 win3 6/11/2013 10:39:40
Device1 win4 6/11/2013 10:39:40
Device1 win5 6/11/2013 10:39:40
As you can see device1 is logged @ different intervals & on different days, but from these logged data i need only the latest logged data i.e, the lower 4 values of the table logged @ 10:39:39 till 10:39:40 & on 6/11/2013. How do i write a query for this case?
You can try querying the table using Top and Order by clause to get the latest 4 records. something like this
SELECT TOP 5 [DeviceName], [WindowName], [LogTime] FROM Device ORDER BY [LogTime] DESC
这篇关于如何从MS Access数据库中检索最新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!