简体   繁体   English

如何在db2中使用最新时间戳记提取列数据/值

[英]How to extract the column data/values with latest timestamp in db2

From below table I want to extract the column values (C_Number) with the latest TimeStamp buy comparing with current system timestamp from db2 table? 我要从下表中提取与db2表中的当前系统时间戳进行比较的最新TimeStamp购买的列值(C_Number)? Please help. 请帮忙。

Example: In Table "Computer" there are 3 columns ie 示例:在“计算机”表中有3列,即

C_Number    |              C_Data      |                TimeStamp
------------------------------------------------------------------------------
12-DFHK     |              Yes         |              2013-08-14 07:33:05.29

13-DFCC     |              Yes         |              2013-08-18 07:45:05.29

Form the above table how can i extract the Column "C_Number" values with latest Timestamp(in this above table latest timestamp is "2013-08-18 07:45:05.29" ) by comparing with current system time. 从上表中,我如何通过与当前系统时间进行比较来提取具有最新时间戳的列“ C_Number”值(在该表中,最新时间戳是“ 2013-08-18 07:45:05.29”)。

SELECT C_Number FROM Computer
WHERE TimeStamp = (SELECT MAX(TimeStamp) FROM Computer);

one more efficient way to achive your purpose is the following: 实现目标的一种更有效的方法如下:

SELECT C_Number
FROM Computer
ORDER BY TimeStamp DESC
FETCH FIRST ROW ONLY ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM